├── codesv-examples
├── aws_s3_virtualized
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ └── test.json
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── ca
│ │ │ │ └── codesv
│ │ │ │ └── codesv_aws_service
│ │ │ │ ├── UnknownValidationResultException.java
│ │ │ │ ├── PutObjectToBucketApp.java
│ │ │ │ ├── ViewModelHolder.java
│ │ │ │ ├── ReportCreatorService.java
│ │ │ │ ├── AppEnv.java
│ │ │ │ ├── PutObjectService.java
│ │ │ │ ├── ViewReportForm.java
│ │ │ │ ├── ValidationResult.java
│ │ │ │ ├── ReportService.java
│ │ │ │ ├── ReportUploadResult.java
│ │ │ │ └── ReportDraft.java
│ │ └── test
│ │ │ ├── resources
│ │ │ ├── test.json
│ │ │ └── keystore.jks
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ca
│ │ │ └── codesv
│ │ │ ├── codesv_aws_service
│ │ │ ├── repository
│ │ │ │ └── S3CodeSvRepoTxnName.java
│ │ │ ├── demo
│ │ │ │ ├── BaseTest.java
│ │ │ │ ├── DemoUtils.java
│ │ │ │ ├── ProcessReportAccessDeniedTest.java
│ │ │ │ ├── ProcessReportOperationAborted.java
│ │ │ │ ├── ProcessReportNoSuchBucketTest.java
│ │ │ │ ├── ProcessReportSuccessTest.java
│ │ │ │ └── ProcessReportParametrizedTest.java
│ │ │ └── backup
│ │ │ │ ├── ProcessReportSuccessRealTest.java
│ │ │ │ ├── ReportServiceTest.java
│ │ │ │ ├── ReportServiceParameterizedTest.java
│ │ │ │ └── ReportServiceCodeSvTest.java
│ │ │ └── model
│ │ │ └── ClassTransactionRepository.java
│ ├── settings.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── build.gradle
│ ├── README.md
│ ├── gradlew.bat
│ └── gradlew
├── build.gradle
├── virtualized-http-examples
│ ├── settings.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── src
│ │ └── test
│ │ │ ├── resources
│ │ │ ├── ssl
│ │ │ │ └── keystore.jks
│ │ │ ├── generatedRRPairs
│ │ │ │ ├── get_portfolio-0-req.txt
│ │ │ │ └── get_portfolio-0-rsp0.txt
│ │ │ ├── log4j2.xml
│ │ │ └── requests
│ │ │ │ └── txt_request.txt
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ca
│ │ │ └── codesv
│ │ │ └── example
│ │ │ ├── PostVerificationExample.java
│ │ │ ├── LambdaExample.java
│ │ │ ├── VerificationExample.java
│ │ │ ├── UrlParameterExample.java
│ │ │ ├── BasicAuthExample.java
│ │ │ ├── AdvancedMatchingExample.java
│ │ │ ├── TemplateReferenceExample.java
│ │ │ ├── ExportExample.java
│ │ │ ├── HttpsExample.java
│ │ │ ├── MagicStringExample.java
│ │ │ ├── GetAndPostExample.java
│ │ │ ├── CurrentMagicDateExample.java
│ │ │ ├── XmlExample.java
│ │ │ ├── ImportExample.java
│ │ │ └── EncodingExample.java
│ ├── README.md
│ ├── build.gradle
│ ├── gradlew.bat
│ └── gradlew
├── springboot-virtualized-soap-example
│ ├── settings.gradle
│ ├── src
│ │ ├── main
│ │ │ ├── resources
│ │ │ │ ├── application.yml
│ │ │ │ └── wsdl
│ │ │ │ │ └── greeting.wsdl
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── ca
│ │ │ │ └── codesv
│ │ │ │ └── ws
│ │ │ │ ├── SpringWsApplication.java
│ │ │ │ ├── client
│ │ │ │ ├── ClientConfig.java
│ │ │ │ └── HelloWorldClient.java
│ │ │ │ └── endpoint
│ │ │ │ ├── HelloWorldEndpoint.java
│ │ │ │ └── WebServiceConfig.java
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ca
│ │ │ └── codesv
│ │ │ └── ws
│ │ │ └── SpringWsApplicationTests.java
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── README.md
│ ├── gradlew.bat
│ ├── build.gradle
│ └── gradlew
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── repositories-example
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── README.md
│ ├── build.gradle
│ ├── src
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ca
│ │ │ └── codesv
│ │ │ └── example
│ │ │ └── repository
│ │ │ ├── repositories
│ │ │ ├── DevRepository.java
│ │ │ ├── QaRepository.java
│ │ │ └── DefaultRepository.java
│ │ │ └── pojo
│ │ │ └── ServiceResult.java
│ ├── gradlew.bat
│ └── gradlew
├── settings.gradle
├── README.md
├── gradlew.bat
└── gradlew
├── wiki
├── images
│ └── gettingstarted_image.png
└── files
│ └── ThirdPartyAcknowledgments.zip
└── README.md
/codesv-examples/aws_s3_virtualized/src/main/resources/test.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/resources/test.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'codesv-aws-service'
2 |
3 |
--------------------------------------------------------------------------------
/codesv-examples/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.ca.codesv'
2 | version '2.0.0'
3 |
4 | apply plugin: 'java'
5 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'virtualized-http-examples'
2 |
3 |
--------------------------------------------------------------------------------
/wiki/images/gettingstarted_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/wiki/images/gettingstarted_image.png
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'springboot-virtualized-soap-example'
2 |
3 |
--------------------------------------------------------------------------------
/wiki/files/ThirdPartyAcknowledgments.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/wiki/files/ThirdPartyAcknowledgments.zip
--------------------------------------------------------------------------------
/codesv-examples/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/resources/keystore.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/aws_s3_virtualized/src/test/resources/keystore.jks
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/aws_s3_virtualized/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/repositories-example/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | client:
2 | default-uri: http://localhost:9090/codesv/ws/greeting
3 |
4 | server:
5 | port: 9090
6 |
--------------------------------------------------------------------------------
/codesv-examples/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'springboot-virtualized-soap-example'
2 | include 'virtualized-http-examples'
3 | include 'repositories-example'
4 | rootProject.name = 'svcode-examples'
5 |
6 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/virtualized-http-examples/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/resources/ssl/keystore.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/virtualized-http-examples/src/test/resources/ssl/keystore.jks
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CA-DevTest/CodeSV/HEAD/codesv-examples/springboot-virtualized-soap-example/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/README.md:
--------------------------------------------------------------------------------
1 | ### CodeSV Repositories example
2 |
3 | This is a sample Gradle project that contains tests to show the capabilities of CodeSV with class repositories feature. All examples are virtualizing HTTP services using a HTTP fluent API.
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/README.md:
--------------------------------------------------------------------------------
1 | ### CodeSV HTTP examples
2 |
3 | This is a sample Gradle project that contains tests to show the capabilities of CodeSV. All examples are virtualizing HTTP services using a HTTP fluent API.
4 |
5 | This project is runnable only with Java 8 and Gradle.
6 |
--------------------------------------------------------------------------------
/codesv-examples/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 09 10:20:45 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
7 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Oct 22 13:47:33 CEST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-bin.zip
7 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 09 10:20:45 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
7 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 09 10:20:45 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
7 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jan 09 10:20:45 CET 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-rc-2-all.zip
7 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/resources/generatedRRPairs/get_portfolio-0-req.txt:
--------------------------------------------------------------------------------
1 | GET /portfolio?year=2016&tokenQuery=X4sPhj15WQE HTTP/1.1
2 | Connection: keep-alive
3 | User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
4 | Host: www.ca.com
5 | Accept-Language: en_us
6 | Accept-Encoding: gzip,deflate
7 | Custom-Header: CustomValue
8 |
9 |
--------------------------------------------------------------------------------
/codesv-examples/README.md:
--------------------------------------------------------------------------------
1 | ### CodeSV Code Examples
2 | These are sample Gradle projects that contain tests to show the capabilities of CodeSV. All examples in these projects are virtualizing HTTP services using a HTTP fluent API.
3 |
4 | These projects are runnable only with Java 8 and Gradle.
5 |
6 | Projects:
7 | * [virtualized-http-example](./virtualized-http-examples/)
8 | * [springboot-virtualized-soap-example](./springboot-virtualized-soap-example/)
9 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/resources/generatedRRPairs/get_portfolio-0-rsp0.txt:
--------------------------------------------------------------------------------
1 | HTTP/1.1 200 OK
2 | Content-Type: application/json
3 |
4 | {"portfolio": {
5 | "id": "1",
6 | "year": "2016",
7 | "productNamesList": [
8 | "CA Server Automation",
9 | "CA Service Catalog",
10 | "CA Service Desk Manager",
11 | "CA Service Management",
12 | "CA Service Operations Insight",
13 | "CA Service Virtualization"
14 | ]
15 | }}
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/java/com/ca/codesv/ws/SpringWsApplication.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.ws;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * SpringBoot application.
8 | */
9 | @SpringBootApplication
10 | public class SpringWsApplication {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(SpringWsApplication.class, args);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/resources/requests/txt_request.txt:
--------------------------------------------------------------------------------
1 | POST /text HTTP/1.1
2 | Accept: text/plain
3 | Accept-Language: zh-cn
4 | Content-Type: text/plain
5 | UA-CPU: x86
6 | User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
7 | Host: localhost
8 | Content-Length: 198
9 | Connection: Keep-Alive
10 | Cache-Control: no-cache
11 | CustomHeader: Header Value
12 |
13 | Success
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.ca.codesv'
2 |
3 | apply plugin: 'java'
4 |
5 | sourceCompatibility = 1.8
6 | targetCompatibility = 1.8
7 |
8 |
9 | repositories {
10 | mavenLocal()
11 | maven { url "http://ca.bintray.com/sv" }
12 | mavenCentral()
13 | }
14 |
15 |
16 | dependencies {
17 | // Logging
18 | compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
19 | compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
20 | compile("com.broadcom.codesv:codesv-dist-jar:2.0.0")
21 |
22 | compile("org.apache.httpcomponents:httpclient:4.5.3")
23 | compile("com.google.code.gson:gson:2.8.0")
24 | compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.10.0'
25 | }
26 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.ca.codesv'
2 | version '2.0.0'
3 |
4 | apply plugin: 'java'
5 |
6 | sourceCompatibility = 1.8
7 | targetCompatibility = 1.8
8 |
9 | repositories {
10 | mavenLocal()
11 | maven { url "http://ca.bintray.com/sv" }
12 | mavenCentral()
13 | }
14 |
15 |
16 | dependencies {
17 | // Logging
18 | compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
19 | compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
20 | compile("com.broadcom.codesv:codesv-dist-jar:2.0.0")
21 |
22 | compile("org.apache.httpcomponents:httpclient:4.5.3")
23 | compile("com.google.code.gson:gson:2.8.0")
24 | compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.10.0'
25 | }
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.ca.codesv'
2 | version '1.0-SNAPSHOT'
3 |
4 | buildscript {
5 | repositories {
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
10 | }
11 | }
12 |
13 | apply plugin: "io.spring.dependency-management"
14 | apply plugin: 'java'
15 |
16 | sourceCompatibility = 1.8
17 |
18 | repositories {
19 | maven {
20 | url "http://ca.bintray.com/sv"
21 | }
22 | mavenCentral()
23 | }
24 |
25 | dependencyManagement {
26 | imports {
27 | mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.228'
28 | }
29 | }
30 |
31 | dependencies {
32 | compile 'com.amazonaws:aws-java-sdk-s3'
33 | compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
34 |
35 | compile 'com.broadcom.codesv:codesv-dist-jar:2.0.0'
36 | testCompile group: 'junit', name: 'junit', version: '4.12'
37 | }
38 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/README.md:
--------------------------------------------------------------------------------
1 | ### Spring Boot virtualized SOAP example
2 |
3 | This is a sample gradle project showing the capabilities of CodeSV at virtualizing SOAP messages with the Spring Boot WS application. This project contains the Spring Boot application that creates a webservice server from a WSDL file and creates a webservice client that can be used for making requests. When the Spring Boot application is running, it exposes the real webservice to the localhost and can be found at `http://localhost:9090/codesv/ws/helloworld.wsdl`.
4 |
5 | Tests in this project contain an example of a real webservice call and also an example of CodeSV virtualizing the SOAP response.
6 |
7 | This project is runnable only with Java 8 and Gradle.
8 |
9 | #### Prerequisite
10 | To successfully compile and run this sample project, you first need to run the Gradle task genJaxb to generate necessary classes:
11 | ```
12 | ./gradlew genJaxb
13 | ```
14 |
15 | #### Running the spring boot application
16 | ```
17 | ./gradlew bootRun
18 | ```
19 |
20 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/README.md:
--------------------------------------------------------------------------------
1 | # AWS S3 Demo virtualization with CodeSV
2 |
3 | In this example, we are going to virtualize the AWS S3 client from AWS SDK to be able to create tests for uncommon edge cases (like AccessDenied, NonExistingBucket or OperationAborted).
4 |
5 | ## How to run it
6 | 1. For running AWS SDK on your local machine, you need to setup your environment (AWS Profile). For more information see this [page](https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/setup-credentials.html).
7 | 2. Create your bucket in AWS S3 to be sure it works with the real endpoint.
8 | 3. Add the host of your AWS S3 bucket to your KeyStore/TrustStore. AWS SDK client works with HTTPS. For tests in this example we are using _keystore.jks_ file from test resources.
9 | 4. Virtualize!
10 |
11 | ## Where are definitions for virtualized endpoints defined?
12 | In this example, we are using our repository feature from CodeSV 1.3 and all our definitions for virtualization are stored in repository classes located in repository package under test folder (_S3CodeSvDemoBucketRepository.java_ and _S3CodeSvRepoTxnName.java_).
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/java/com/ca/codesv/ws/client/ClientConfig.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.ws.client;
2 |
3 | import org.springframework.beans.factory.annotation.Value;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.oxm.jaxb.Jaxb2Marshaller;
7 | import org.springframework.ws.client.core.WebServiceTemplate;
8 |
9 | /**
10 | * Client configuration.
11 | */
12 | @Configuration
13 | public class ClientConfig {
14 |
15 | @Value("${client.default-uri}")
16 | private String defaultUri;
17 |
18 | /**
19 | * Setups marshaller bean.
20 | *
21 | * @return jaxb marshaller
22 | */
23 | @Bean
24 | Jaxb2Marshaller jaxb2Marshaller() {
25 | Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
26 | jaxb2Marshaller.setContextPath("com.ca.codesv.types.greeting");
27 |
28 | return jaxb2Marshaller;
29 | }
30 |
31 | /**
32 | * Setups webservice template.
33 | *
34 | * @return webservice template
35 | */
36 | @Bean
37 | public WebServiceTemplate webServiceTemplate() {
38 | WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
39 | webServiceTemplate.setMarshaller(jaxb2Marshaller());
40 | webServiceTemplate.setUnmarshaller(jaxb2Marshaller());
41 | webServiceTemplate.setDefaultUri(defaultUri);
42 |
43 | return webServiceTemplate;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/repository/S3CodeSvRepoTxnName.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.repository;
24 |
25 | public class S3CodeSvRepoTxnName {
26 | public static final String ACCESS_DENIED = "access denied";
27 | }
28 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/UnknownValidationResultException.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | public class UnknownValidationResultException extends Exception {
26 |
27 | public UnknownValidationResultException(String message) {
28 | super(message);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/java/com/ca/codesv/ws/client/HelloWorldClient.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.ws.client;
2 |
3 | import com.ca.codesv.types.greeting.Greeting;
4 | import com.ca.codesv.types.greeting.ObjectFactory;
5 | import com.ca.codesv.types.greeting.Person;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.ws.client.core.WebServiceTemplate;
11 |
12 | /**
13 | * Webservice client.
14 | */
15 | @Component
16 | public class HelloWorldClient {
17 |
18 | private static final Logger LOGGER = LoggerFactory.getLogger(HelloWorldClient.class);
19 |
20 | @Autowired
21 | private WebServiceTemplate webServiceTemplate;
22 |
23 | /**
24 | * Sending request to the webservice.
25 | *
26 | * @param firstName first name
27 | * @param lastName last name
28 | *
29 | * @return response from webservice
30 | */
31 | public String sayHello(String firstName, String lastName) {
32 | ObjectFactory factory = new ObjectFactory();
33 | Person person = factory.createPerson();
34 |
35 | person.setFirstName(firstName);
36 | person.setLastName(lastName);
37 |
38 | LOGGER.info("Client sending person[firstName={},lastName={}]", person.getFirstName(),
39 | person.getLastName());
40 |
41 | Greeting greeting = (Greeting) webServiceTemplate.marshalSendAndReceive(person);
42 |
43 | LOGGER.info("Client received greeting='{}'", greeting.getGreeting());
44 | return greeting.getGreeting();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/java/com/ca/codesv/ws/endpoint/HelloWorldEndpoint.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.ws.endpoint;
2 |
3 | import com.ca.codesv.types.greeting.Greeting;
4 | import com.ca.codesv.types.greeting.ObjectFactory;
5 | import com.ca.codesv.types.greeting.Person;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.ws.server.endpoint.annotation.Endpoint;
9 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
10 | import org.springframework.ws.server.endpoint.annotation.RequestPayload;
11 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
12 |
13 | /**
14 | * Webservice endpoint.
15 | */
16 | @Endpoint
17 | public class HelloWorldEndpoint {
18 |
19 | private static final Logger LOGGER = LoggerFactory.getLogger(HelloWorldEndpoint.class);
20 |
21 | /**
22 | * Webservice endpoint.
23 | *
24 | * @param request request
25 | *
26 | * @return generated greeting
27 | */
28 | @PayloadRoot(namespace = "http://codesv.ca.com/types/greeting", localPart = "person")
29 | @ResponsePayload
30 | public Greeting sayHello(@RequestPayload Person request) {
31 | LOGGER.info("Endpoint received person[firstName={},lastName={}]", request.getFirstName(),
32 | request.getLastName());
33 |
34 | String greeting = "Hello " + request.getFirstName() + " " + request.getLastName() + "!";
35 |
36 | ObjectFactory factory = new ObjectFactory();
37 | Greeting response = factory.createGreeting();
38 | response.setGreeting(greeting);
39 |
40 | LOGGER.info("Endpoint sending greeting='{}'", response.getGreeting());
41 | return response;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/PutObjectToBucketApp.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.codesv_aws_service; /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | import java.io.File;
24 |
25 | public class PutObjectToBucketApp {
26 |
27 | public static void main(String[] args) {
28 | PutObjectService putObjectService = PutObjectService.getInstance();
29 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
30 | File fileToUpload =new File(classLoader.getResource("test.json").getFile());
31 |
32 | putObjectService.putFileToBucket("codesvdemobucket", "MyTest", fileToUpload);
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/java/com/ca/codesv/ws/endpoint/WebServiceConfig.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.ws.endpoint;
2 |
3 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.core.io.ClassPathResource;
8 | import org.springframework.ws.config.annotation.EnableWs;
9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter;
10 | import org.springframework.ws.transport.http.MessageDispatcherServlet;
11 | import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
12 | import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
13 |
14 | /**
15 | * Webservice configuration.
16 | */
17 | @EnableWs
18 | @Configuration
19 | public class WebServiceConfig extends WsConfigurerAdapter {
20 |
21 | /**
22 | * Setup servlet registration bean.
23 | *
24 | * @param applicationContext context
25 | *
26 | * @return servlet registration bean
27 | */
28 | @Bean
29 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
30 | MessageDispatcherServlet servlet = new MessageDispatcherServlet();
31 | servlet.setApplicationContext(applicationContext);
32 |
33 | return new ServletRegistrationBean(servlet, "/codesv/ws/*");
34 | }
35 |
36 | /**
37 | * Setups basic webservice defined by default wsdl.
38 | *
39 | * @return wsdl definition
40 | */
41 | @Bean(name = "helloworld")
42 | public Wsdl11Definition defaultWsdl11Definition() {
43 | SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
44 | wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/greeting.wsdl"));
45 |
46 | return wsdl11Definition;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/BaseTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import com.ca.codesv.codesv_aws_service.ViewReportForm;
26 | import org.junit.Before;
27 |
28 | public abstract class BaseTest {
29 |
30 | protected ViewReportForm reportForm = new ViewReportForm();
31 |
32 | @Before
33 | public void setUp() {
34 | reportForm.setApplicationNameInput("My application");
35 | reportForm.setDescriptionTextArea("Testing description!");
36 | reportForm.setEnvHostInput("localhost");
37 | reportForm.setEnvNameInput("Dev env");
38 | reportForm.setReportNameInput("My application report");
39 | }
40 |
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CodeSV
2 |
3 | ### End of Life Feature as of February 1, 2023
4 | _*Effective February 1, 2023, CodeSV will be deprecated. CodeSV will be supported until Jan 31st, 2023.*_
5 |
6 |
7 | CA CodeSV is a new, lightweight way to define virtual services and save valuable time.
8 |
9 | At the core, CodeSV delivers a simple yet powerful Java library that provides an easy to use API so you can create and run virtual services as a part of jUnit testing.
10 |
11 | You can create and run HTTP virtual service definitions directly in your unit testing code.
12 |
13 | Even better, the HTTP virtual services are completely transparent to an application under test. This means you don't have to make any other configuration tweaks.
14 |
15 | [How to use CodeSV](https://github.com/CA-DevTest/CodeSV/wiki/Quick-Start-Guide)
16 |
17 | [Share ideas and raise issues](https://communities.ca.com/community/ca-devtest-community/content?filterID=contentstatus%5Bpublished%5D~category%5Bsv-as-code%5D)
18 |
19 |
20 | ## Code Example
21 | Here is a simple example of a jUnit test running an embedded virtual service using CodeSV.
22 |
23 | ```java
24 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.*;
25 | import static org.junit.Assert.*;
26 |
27 | import com.ca.codesv.engine.junit4.VirtualServerRule;
28 | import org.junit.*;
29 |
30 | public class ExampleTest {
31 |
32 | @Rule
33 | public VirtualServerRule vs = new VirtualServerRule();
34 |
35 | @Test
36 | public void exampleTest() {
37 | // virtual service definition
38 | forGet("http://www.example.com/time").doReturn(
39 | okMessage()
40 | .withJsonBody("{\"timestamp\":1498838896}")
41 | );
42 |
43 | // application connects to http://www.example.com/test and retrieves JSON response
44 | int currentTimestamp = Application.retrieveCurrentTimestamp();
45 |
46 | // received timestamp check
47 | assertEquals(1498838896, currentTimestamp);
48 | }
49 | }
50 | ```
51 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/DemoUtils.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import java.util.Arrays;
26 | import java.util.Collection;
27 | import java.util.List;
28 |
29 | public final class DemoUtils {
30 |
31 | private DemoUtils() {
32 | //utility class
33 | }
34 |
35 | public static Collection prepareParameters(List transactionNames) {
36 | String[][] params = new String[transactionNames.size()][2];
37 |
38 |
39 | for (int i = 0; i < params.length; i++) {
40 | params[i][0] = transactionNames.get(i);
41 | params[i][1] ="MyTest" + (i + 1);
42 | }
43 |
44 | return Arrays.asList(params);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ViewModelHolder.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | import java.util.HashMap;
26 | import java.util.Map;
27 |
28 | public class ViewModelHolder {
29 |
30 | public static final String PROCESS_RESULT = "processResult";
31 | public static final String PROCESS_RESULT_DETAIL = "processResultDetail";
32 |
33 | Map viewAttributes = new HashMap<>();
34 |
35 | public ViewModelHolder() {
36 | }
37 |
38 | public void addValidatedResult(ValidationResult validationResult) {
39 | viewAttributes.put(PROCESS_RESULT, validationResult.getAwsCode());
40 | viewAttributes.put(PROCESS_RESULT_DETAIL, validationResult.getMessage());
41 | }
42 |
43 |
44 | public Map getViewAttributes() {
45 | return viewAttributes;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/backup/ProcessReportSuccessRealTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.backup;
24 |
25 | import com.ca.codesv.codesv_aws_service.*;
26 | import org.junit.Test;
27 |
28 | import java.util.UUID;
29 |
30 | import static org.junit.Assert.assertTrue;
31 |
32 | public class ProcessReportSuccessRealTest {
33 |
34 | @Test
35 | public void processReportSuccess() {
36 | ReportDraft reportDraft = new ReportDraft("My testing report",
37 | "My Application",
38 | "Lorem ipsum",
39 | new AppEnv("dev_env", "localhost"));
40 |
41 | final String reportKey = "Report - " + UUID.randomUUID().toString();
42 |
43 | ReportUploadResult result = ReportService.getInstance().processReport(reportDraft, reportKey);
44 |
45 | assertTrue(result.isSuccess());
46 | }
47 | }
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/backup/ReportServiceTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.backup;
24 |
25 | import com.ca.codesv.codesv_aws_service.AppEnv;
26 | import com.ca.codesv.codesv_aws_service.ReportDraft;
27 | import com.ca.codesv.codesv_aws_service.ReportService;
28 | import com.ca.codesv.codesv_aws_service.ReportUploadResult;
29 | import org.junit.Test;
30 |
31 | import java.util.UUID;
32 |
33 | import static org.junit.Assert.assertTrue;
34 |
35 | public class ReportServiceTest {
36 |
37 | @Test
38 | public void processReportWithoutVirtualizedService() {
39 | ReportDraft reportDraft = new ReportDraft("My testing report",
40 | "My Application",
41 | "Lorem ipsum",
42 | new AppEnv("dev_env", "localhost"));
43 |
44 | final String reportKey = "Report - " + UUID.randomUUID().toString();
45 |
46 | ReportUploadResult result = ReportService.getInstance().processReport(reportDraft, reportKey);
47 |
48 | assertTrue(result.isSuccess());
49 | }
50 | }
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ReportCreatorService.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | public class ReportCreatorService {
26 | private static ReportCreatorService instance;
27 |
28 | private ReportCreatorService() {
29 | }
30 |
31 | public static ReportCreatorService getInstance() {
32 | if (instance == null) {
33 | synchronized (ReportCreatorService.class) {
34 | if (instance == null) {
35 | instance = new ReportCreatorService();
36 | }
37 | }
38 | }
39 | return instance;
40 | }
41 |
42 | public ValidationResult uploadReport(ReportDraft reportDraft, String reportName) throws UnknownValidationResultException{
43 | ReportUploadResult result = ReportService.getInstance().processReport(reportDraft, reportName);
44 |
45 | if (result.isSuccess()) {
46 | return ValidationResult.UPLOADED;
47 | } else {
48 | return ValidationResult.findValueByAwsCode(result.getErrorCode());
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/AppEnv.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | import java.util.Objects;
26 |
27 | public class AppEnv {
28 | private String name;
29 | private String host;
30 |
31 | public AppEnv(String name, String host) {
32 | this.name = name;
33 | this.host = host;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public void setName(String name) {
41 | this.name = name;
42 | }
43 |
44 | public String getHost() {
45 | return host;
46 | }
47 |
48 | public void setHost(String host) {
49 | this.host = host;
50 | }
51 |
52 | @Override
53 | public boolean equals(Object o) {
54 | if (this == o) return true;
55 | if (o == null || getClass() != o.getClass()) return false;
56 | AppEnv appEnv = (AppEnv) o;
57 | return Objects.equals(name, appEnv.name) &&
58 | Objects.equals(host, appEnv.host);
59 | }
60 |
61 | @Override
62 | public int hashCode() {
63 | return Objects.hash(name, host);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/src/test/java/com/ca/codesv/example/repository/repositories/DevRepository.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example.repository.repositories;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 |
28 | import com.ca.codesv.example.repository.pojo.ServiceResult;
29 | import com.ca.codesv.sdk.annotation.TransactionDefinition;
30 | import com.ca.codesv.sdk.annotation.VirtualServiceRepository;
31 | import com.google.gson.Gson;
32 |
33 | /**
34 | * Dev repository.
35 | *
36 | * @author CA
37 | */
38 | @VirtualServiceRepository(serviceName = "Dev service")
39 | public class DevRepository {
40 | @TransactionDefinition(name = "simpleResponse", tags = {"COMMON", "DEV"})
41 | public void virtualizedSimpleDefaultResponse() {
42 | ServiceResult result = new ServiceResult();
43 | result.setTags("COMMON", "DEV");
44 | result.setTxnName("simpleResponse");
45 | result.setVsName("Dev service");
46 |
47 | forGet(DefaultRepository.SERVICE_URL + "/simpleDefaultService").doReturn(
48 | okMessage()
49 | .withJsonBody(new Gson().toJson(result))
50 | );
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/src/test/java/com/ca/codesv/example/repository/repositories/QaRepository.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example.repository.repositories;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 |
28 | import com.ca.codesv.example.repository.pojo.ServiceResult;
29 | import com.ca.codesv.sdk.annotation.TransactionDefinition;
30 | import com.ca.codesv.sdk.annotation.VirtualServiceRepository;
31 | import com.google.gson.Gson;
32 |
33 | /**
34 | * QA repository.
35 | *
36 | * @author CA
37 | */
38 | @VirtualServiceRepository(serviceName = "Qa service")
39 | public class QaRepository {
40 |
41 | @TransactionDefinition(name = "simpleResponse", tags = {"COMMON", "QA"})
42 | public void virtualizedSimpleDefaultResponse() {
43 | ServiceResult result = new ServiceResult();
44 | result.setTags("COMMON", "QA");
45 | result.setTxnName("simpleResponse");
46 | result.setVsName("Qa service");
47 |
48 | forGet(DefaultRepository.SERVICE_URL + "/simpleDefaultService").doReturn(
49 | okMessage()
50 | .withJsonBody(new Gson().toJson(result))
51 | );
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/test/java/com/ca/codesv/ws/SpringWsApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.ca.codesv.ws;
2 |
3 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forPost;
4 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
5 | import static org.assertj.core.api.Assertions.assertThat;
6 | import static org.junit.Assert.assertEquals;
7 |
8 | import com.ca.codesv.engine.junit4.VirtualServerRule;
9 | import com.ca.codesv.ws.client.HelloWorldClient;
10 | import org.junit.Before;
11 | import org.junit.Rule;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.boot.test.context.SpringBootTest;
16 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
17 | import org.springframework.test.context.junit4.SpringRunner;
18 |
19 | /**
20 | * Test showing real webservice call and virtualized one.
21 | */
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
24 | public class SpringWsApplicationTests {
25 |
26 | @Autowired
27 | private HelloWorldClient helloWorldClient;
28 |
29 | @Rule
30 | public VirtualServerRule serverRule = new VirtualServerRule();
31 |
32 | @Before
33 | public void setUp() throws Exception {
34 | Thread.sleep(5000);
35 | }
36 |
37 | @Test
38 | public void testRealService() throws InterruptedException {
39 | assertThat(helloWorldClient.sayHello("John", "Doe")).isEqualTo("Hello John Doe!");
40 | }
41 |
42 | @Test
43 | public void testVirtualizedService() {
44 | String virtualizedResponse = "Greeting from virtualized service, John Doe!";
45 | String body =
46 | "\n"
47 | + " \n"
48 | + " \n"
49 | + " \n"
50 | + " " + virtualizedResponse + "\n"
51 | + " \n"
52 | + " \n"
53 | + "";
54 |
55 | forPost("http://localhost:9090/codesv/ws/greeting").doReturn(
56 | okMessage()
57 | .withContentType("text/xml; charset=utf-8")
58 | .withBody(body.getBytes())
59 | );
60 |
61 | String responseGreeting = helloWorldClient.sayHello("John", "Doe");
62 | assertEquals(responseGreeting, virtualizedResponse);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/codesv-examples/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/PutObjectService.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | import com.amazonaws.AmazonServiceException;
26 | import com.amazonaws.auth.profile.ProfileCredentialsProvider;
27 | import com.amazonaws.services.s3.AmazonS3;
28 | import com.amazonaws.services.s3.AmazonS3ClientBuilder;
29 | import com.amazonaws.services.s3.model.AmazonS3Exception;
30 |
31 | import java.io.File;
32 |
33 | public class PutObjectService {
34 |
35 | private static PutObjectService instance;
36 | public AmazonS3 s3;
37 |
38 | private PutObjectService() {
39 | s3 = AmazonS3ClientBuilder.standard()
40 | .withCredentials(
41 | new ProfileCredentialsProvider("codesv_demo"))
42 | .build();
43 | }
44 |
45 | public static PutObjectService getInstance() {
46 | if (instance == null) {
47 | instance = new PutObjectService();
48 | }
49 | return instance;
50 | }
51 |
52 | public boolean putFileToBucket(String bucketName, String key, File fileToUpload) {
53 | try {
54 | s3.putObject(bucketName, key, fileToUpload);
55 | } catch (AmazonS3Exception e) {
56 | return false;
57 | }
58 | return true;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/src/main/resources/wsdl/greeting.wsdl:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
50 |
51 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 | Hello World service
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'idea'
3 | apply plugin: 'org.springframework.boot'
4 | apply plugin: 'maven'
5 |
6 | group 'com.ca.codesv'
7 |
8 | buildscript {
9 | repositories {
10 | mavenLocal()
11 | maven { url "http://ca.bintray.com/sv" }
12 | mavenCentral()
13 | }
14 | dependencies {
15 | classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
16 | }
17 | }
18 |
19 |
20 | configurations {
21 | jaxb
22 | jaxws
23 | }
24 |
25 |
26 | repositories {
27 | mavenLocal()
28 | maven { url "http://ca.bintray.com/sv" }
29 | mavenCentral()
30 | }
31 |
32 | task genJaxb {
33 | ext.destDir = file("${buildDir}/generated-sources/jaxb")
34 | ext.classesDir = "${buildDir}/classes/jaxb"
35 | doLast {
36 | ant {
37 | mkdir(dir: sourceSets.main.output.classesDir)
38 | mkdir(dir: destDir)
39 | mkdir(dir: classesDir)
40 | taskdef(name: 'wsimport',
41 | classname: 'com.sun.tools.ws.ant.WsImport',
42 | classpath: configurations.jaxws.asPath
43 | )
44 | wsimport(keep: true,
45 | destdir: sourceSets.main.output.classesDir,
46 | sourcedestdir: destDir,
47 | extension: "true",
48 | verbose: "false",
49 | quiet: "false",
50 | package: "com.ca.codesv.types.greeting",
51 | xnocompile: "true",
52 | wsdl: "${projectDir}/src/main/resources/wsdl/greeting.wsdl") {
53 | xjcarg(value: "-XautoNameResolution")
54 | }
55 |
56 | javac(destdir: classesDir, source: 1.6, target: 1.6, debug: true,
57 | debugLevel: "lines,vars,source",
58 | classpath: configurations.jaxb.asPath) {
59 | src(path: destDir)
60 | include(name: "**/*.java")
61 | include(name: "*.java")
62 | }
63 | }
64 | }
65 | }
66 |
67 | sourceCompatibility = 1.8
68 | targetCompatibility = 1.8
69 |
70 | ext['jetty.version'] = '9.2.17.v20160517'
71 |
72 | dependencies {
73 | compile("org.springframework.boot:spring-boot-starter")
74 | compile("org.springframework.boot:spring-boot-starter-test")
75 | compile("org.springframework.boot:spring-boot-starter-web-services")
76 | compile(files(genJaxb.classesDir).builtBy(genJaxb))
77 |
78 | jaxb("com.sun.xml.bind:jaxb-xjc:2.1.7")
79 | jaxws('com.sun.xml.ws:jaxws-tools:2.1.4')
80 |
81 | testCompile("junit:junit:4.12")
82 | testCompile("com.broadcom.codesv:codesv-dist-jar:2.0.0")
83 | }
84 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ViewReportForm.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | public class ViewReportForm {
26 |
27 | private String reportNameInput;
28 | private String applicationNameInput;
29 | private String descriptionTextArea;
30 | private String envNameInput;
31 | private String envHostInput;
32 |
33 | public ViewReportForm() {
34 | }
35 |
36 | public String getReportNameInput() {
37 | return reportNameInput;
38 | }
39 |
40 | public void setReportNameInput(String reportNameInput) {
41 | this.reportNameInput = reportNameInput;
42 | }
43 |
44 | public String getApplicationNameInput() {
45 | return applicationNameInput;
46 | }
47 |
48 | public void setApplicationNameInput(String applicationNameInput) {
49 | this.applicationNameInput = applicationNameInput;
50 | }
51 |
52 | public String getDescriptionTextArea() {
53 | return descriptionTextArea;
54 | }
55 |
56 | public void setDescriptionTextArea(String descriptionTextArea) {
57 | this.descriptionTextArea = descriptionTextArea;
58 | }
59 |
60 | public String getEnvNameInput() {
61 | return envNameInput;
62 | }
63 |
64 | public void setEnvNameInput(String envNameInput) {
65 | this.envNameInput = envNameInput;
66 | }
67 |
68 | public String getEnvHostInput() {
69 | return envHostInput;
70 | }
71 |
72 | public void setEnvHostInput(String envHostInput) {
73 | this.envHostInput = envHostInput;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/src/test/java/com/ca/codesv/example/repository/pojo/ServiceResult.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example.repository.pojo;
24 |
25 | /**
26 | * POJO class used for tests with class repositories.
27 | *
28 | * @author CA
29 | */
30 | public class ServiceResult {
31 |
32 | private String txnName;
33 | private String[] tags;
34 | private String vsName;
35 |
36 | public ServiceResult() {
37 | }
38 |
39 | public String getTxnName() {
40 | return txnName;
41 | }
42 |
43 | public void setTxnName(String txnName) {
44 | this.txnName = txnName;
45 | }
46 |
47 | public String[] getTags() {
48 | return tags;
49 | }
50 |
51 | public void setTags(String... tags) {
52 | this.tags = tags;
53 | }
54 |
55 | public String getVsName() {
56 | return vsName;
57 | }
58 |
59 | public void setVsName(String vsName) {
60 | this.vsName = vsName;
61 | }
62 |
63 | @Override
64 | public boolean equals(Object o) {
65 | if (this == o) {
66 | return true;
67 | }
68 | if (o == null || getClass() != o.getClass()) {
69 | return false;
70 | }
71 |
72 | ServiceResult that = (ServiceResult) o;
73 |
74 | if (getTxnName() != null ? !getTxnName().equals(that.getTxnName())
75 | : that.getTxnName() != null) {
76 | return false;
77 | }
78 | if (!getTags().equals(that.getTags())) {
79 | return false;
80 | }
81 | return getVsName().equals(that.getVsName());
82 | }
83 |
84 | @Override
85 | public int hashCode() {
86 | int result = getTxnName() != null ? getTxnName().hashCode() : 0;
87 | result = 31 * result + getTags().hashCode();
88 | result = 31 * result + getVsName().hashCode();
89 | return result;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ValidationResult.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 | package com.ca.codesv.codesv_aws_service;
23 |
24 | public enum ValidationResult {
25 | UPLOADED("", 200, "Report has been uploaded"),
26 | //ERROR_ACCESS_DENIED("AccessDenied", 403, "Access Denied."),
27 | //ERROR_OPERATION_ABORTED("OperationAborted", 409, "Operation was aborted."),
28 | ERROR_NONEXISTING_BUCKET("NoSuchBucket", 404, "Bucket does NOT exist.");
29 |
30 |
31 | private String awsCode;
32 | private int httpCode;
33 | private String message;
34 |
35 | ValidationResult(String code, int httpCode, String message) {
36 | this.awsCode = code;
37 | this.httpCode = httpCode;
38 | this.message = message;
39 | }
40 |
41 | public String getAwsCode() {
42 | return awsCode;
43 | }
44 |
45 | public void setAwsCode(String awsCode) {
46 | this.awsCode = awsCode;
47 | }
48 |
49 | public int getHttpCode() {
50 | return httpCode;
51 | }
52 |
53 | public void setHttpCode(int httpCode) {
54 | this.httpCode = httpCode;
55 | }
56 |
57 | public String getMessage() {
58 | return message;
59 | }
60 |
61 | public void setMessage(String message) {
62 | this.message = message;
63 | }
64 |
65 | public static ValidationResult findValueByAwsCode(String code) throws UnknownValidationResultException{
66 | for (ValidationResult result : values()) {
67 | if (result.awsCode.equalsIgnoreCase(code)) {
68 | return result;
69 | }
70 | }
71 | throw new UnknownValidationResultException("Unknown response from AWS for code " + code);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ReportService.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | import com.amazonaws.AmazonServiceException;
26 | import com.amazonaws.auth.profile.ProfileCredentialsProvider;
27 | import com.amazonaws.services.s3.AmazonS3;
28 | import com.amazonaws.services.s3.AmazonS3ClientBuilder;
29 | import com.amazonaws.services.s3.model.PutObjectResult;
30 | import com.google.gson.Gson;
31 | import com.google.gson.GsonBuilder;
32 |
33 | public class ReportService {
34 |
35 | private static ReportService instance;
36 | private static final Gson gson = new GsonBuilder().create();
37 | private AmazonS3 s3;
38 |
39 | private ReportService() {
40 | }
41 |
42 | public static ReportService getInstance() {
43 | if (instance == null) {
44 | instance = new ReportService();
45 | }
46 | return instance;
47 | }
48 |
49 | public ReportUploadResult processReport(ReportDraft reportDraft) {
50 | return processReport(reportDraft, "MyTest");
51 | }
52 |
53 | public ReportUploadResult processReport(ReportDraft reportDraft, String reportName) {
54 | s3 = AmazonS3ClientBuilder.standard()
55 | .withCredentials(
56 | new ProfileCredentialsProvider("codesv_demo"))
57 | .build();
58 |
59 | String jsonReport = gson.toJson(reportDraft);
60 | try {
61 | PutObjectResult result = s3.putObject("codesvdemobucket", reportName, jsonReport);
62 | } catch (AmazonServiceException ex) {
63 | return new ReportUploadResult(ex.getErrorCode(), ex.getErrorMessage());
64 | }
65 |
66 | return new ReportUploadResult(jsonReport);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/PostVerificationExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.verifyGet;
27 |
28 | import com.ca.codesv.engine.junit4.VirtualServerRule;
29 | import com.ca.codesv.protocols.http.fluent.HttpFluentInterface;
30 | import java.io.IOException;
31 | import org.apache.http.client.HttpClient;
32 | import org.apache.http.client.methods.HttpGet;
33 | import org.apache.http.impl.client.HttpClientBuilder;
34 | import org.junit.Rule;
35 | import org.junit.Test;
36 |
37 | /**
38 | * Example showing post verifications of requests.
39 | *
40 | * @author CA
41 | */
42 | public class PostVerificationExample {
43 |
44 | private static final String BASE_URL = "http://www.ca.com/portfolio";
45 | private static final String QUERY = "?year=2016";
46 | private static final String URL = BASE_URL + "/{id}" + QUERY;
47 |
48 |
49 | @Rule
50 | public VirtualServerRule vs = new VirtualServerRule();
51 |
52 | @Test
53 | public void testPostVerification() throws IOException {
54 | HttpFluentInterface.forGet(URL)
55 | .doReturn(
56 | okMessage()
57 | .withStringBody("Success")
58 | );
59 |
60 | HttpClient client = HttpClientBuilder.create().build();
61 | HttpGet request1 = new HttpGet(BASE_URL + "/1" + QUERY);
62 | client.execute(request1);
63 |
64 | HttpClient client2 = HttpClientBuilder.create().build();
65 | HttpGet request2 = new HttpGet(BASE_URL + "/2" + QUERY);
66 | client2.execute(request2);
67 | client2.execute(request2);
68 |
69 | verifyGet(URL).invoked(3);
70 | verifyGet(BASE_URL + "/1").invoked(1);
71 | verifyGet(BASE_URL + "/2").invoked(2);
72 | verifyGet(URL).matchesQuery("year", "2016").invoked(3);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/LambdaExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 | import static junit.framework.TestCase.assertNotNull;
28 | import static org.junit.Assert.assertEquals;
29 |
30 | import com.ca.codesv.engine.junit4.VirtualServerRule;
31 | import java.io.BufferedReader;
32 | import java.io.InputStreamReader;
33 | import org.apache.http.HttpResponse;
34 | import org.apache.http.client.HttpClient;
35 | import org.apache.http.client.methods.HttpGet;
36 | import org.apache.http.impl.client.HttpClientBuilder;
37 | import org.junit.Rule;
38 | import org.junit.Test;
39 |
40 | /**
41 | * Example showing usage of Java 8 features.
42 | *
43 | * @author CA
44 | */
45 | public class LambdaExample {
46 |
47 | private static final String URL = "http://www.ca.com/portfolio?year=2016&tokenQuery=X4sPhj15WQE";
48 |
49 | @Rule
50 | public VirtualServerRule vs = new VirtualServerRule();
51 |
52 |
53 | @Test
54 | public void testLambda() throws Exception {
55 | forGet(URL)
56 | .matchesHeader("Custom-Header", s -> s.equals("CustomValue"))
57 | .doReturn(
58 | okMessage()
59 | .withJsonBody("Success"));
60 |
61 | HttpClient client = HttpClientBuilder.create().build();
62 | HttpGet request = new HttpGet(URL);
63 | request.addHeader("Custom-Header", "CustomValue");
64 |
65 | HttpResponse response = client.execute(request);
66 |
67 | BufferedReader reader = new BufferedReader(
68 | new InputStreamReader(response.getEntity().getContent()));
69 | StringBuffer result = new StringBuffer();
70 | String line;
71 | while ((line = reader.readLine()) != null) {
72 | result.append(line);
73 | }
74 |
75 | String body = result.toString();
76 |
77 | assertEquals(200, response.getStatusLine().getStatusCode());
78 | assertNotNull(body);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/VerificationExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.contains;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
28 |
29 | import com.ca.codesv.engine.junit4.VirtualServerRule;
30 | import org.apache.http.client.HttpClient;
31 | import org.apache.http.client.methods.HttpGet;
32 | import org.apache.http.impl.client.HttpClientBuilder;
33 | import org.junit.Rule;
34 | import org.junit.Test;
35 |
36 | /**
37 | * Example showing verification of invocation count.
38 | *
39 | * @author CA
40 | */
41 | public class VerificationExample {
42 |
43 | private static final String URL = "http://www.ca.com/portfolio";
44 |
45 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
46 | + "\"portfolio\": {\n"
47 | + " \"id\": \"1\",\n"
48 | + " \"year\": \"{{argument.year}}\",\n"
49 | + " \"productNamesList\": [\n"
50 | + " \"CA Server Automation\",\n"
51 | + " \"CA Service Catalog\",\n"
52 | + " \"CA Service Desk Manager\",\n"
53 | + " \"CA Service Management\",\n"
54 | + " \"CA Service Operations Insight\",\n"
55 | + " \"CA Service Virtualization\"\n"
56 | + " ]\n"
57 | + "}}";
58 |
59 | @Rule
60 | public VirtualServerRule vs = new VirtualServerRule();
61 |
62 |
63 | @Test
64 | public void testInvokedCount() throws Exception {
65 | forGet(URL)
66 | .matchesHeader("Accept-Language", contains("us"))
67 | .doReturn(
68 | okMessage()
69 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
70 | ).invoked(2);
71 |
72 | HttpClient client = HttpClientBuilder.create().build();
73 | HttpGet request = new HttpGet(URL);
74 | request.addHeader("Accept-Language", "en_us");
75 |
76 | client.execute(request);
77 | client.execute(request);
78 | }
79 | }
80 |
81 |
82 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/ProcessReportAccessDeniedTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import com.ca.codesv.codesv_aws_service.*;
26 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
27 | import com.ca.codesv.engine.junit4.VirtualServerRule;
28 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
29 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
30 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
31 | import org.junit.Rule;
32 | import org.junit.Test;
33 |
34 | import static org.junit.Assert.assertEquals;
35 | import static org.junit.Assert.assertNotNull;
36 |
37 |
38 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
39 | public class ProcessReportAccessDeniedTest extends BaseTest {
40 |
41 | @Rule
42 | public VirtualServerRule vs = new VirtualServerRule();
43 |
44 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
45 |
46 | @Test
47 | public void processReportForm() throws Exception {
48 | store.useTransaction(S3CodeSvDemoBucketRepository.ACCESS_DENIED_TXN);
49 |
50 | // Prepare view model which needs to be tested
51 | ViewModelHolder viewModelHolder = new ViewModelHolder();
52 |
53 | // Convert form POJO to ReportDraft POJO
54 | ReportDraft reportDraft = new ReportDraft(
55 | reportForm.getReportNameInput(),
56 | reportForm.getApplicationNameInput(),
57 | reportForm.getDescriptionTextArea(),
58 | new AppEnv(reportForm.getEnvNameInput(), reportForm.getEnvHostInput()));
59 |
60 | // Use creator service to process draft, upload to S3 as MyTest object to prepared bucket and get custom result validation
61 | ValidationResult validationResult =
62 | ReportCreatorService.getInstance().uploadReport(reportDraft, "MyTest3");
63 |
64 | assertNotNull("Validation result cannot be null.", validationResult);
65 |
66 | assertEquals(validationResult.getHttpCode(), 403);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ReportUploadResult.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | import java.util.Objects;
26 |
27 | public class ReportUploadResult {
28 | private boolean success;
29 | private String errorCode;
30 | private String errorDescription;
31 | private String content;
32 |
33 | public ReportUploadResult(String errorCode, String errorDescription) {
34 | this.success = false;
35 | this.errorCode = errorCode;
36 | this.errorDescription = errorDescription;
37 | this.content = "";
38 | }
39 |
40 | public ReportUploadResult(String content) {
41 | this.success = true;
42 | this.errorCode = "";
43 | this.errorDescription = "";
44 | this.content = content;
45 | }
46 |
47 | public boolean isSuccess() {
48 | return success;
49 | }
50 |
51 | public void setSuccess(boolean success) {
52 | this.success = success;
53 | }
54 |
55 | public String getErrorCode() {
56 | return errorCode;
57 | }
58 |
59 | public void setErrorCode(String errorCode) {
60 | this.errorCode = errorCode;
61 | }
62 |
63 | public String getErrorDescription() {
64 | return errorDescription;
65 | }
66 |
67 | public void setErrorDescription(String errorDescription) {
68 | this.errorDescription = errorDescription;
69 | }
70 |
71 | public String getContent() {
72 | return content;
73 | }
74 |
75 | public void setContent(String content) {
76 | this.content = content;
77 | }
78 |
79 | @Override
80 | public boolean equals(Object o) {
81 | if (this == o) return true;
82 | if (o == null || getClass() != o.getClass()) return false;
83 | ReportUploadResult that = (ReportUploadResult) o;
84 | return success == that.success &&
85 | Objects.equals(errorCode, that.errorCode) &&
86 | Objects.equals(errorDescription, that.errorDescription) &&
87 | Objects.equals(content, that.content);
88 | }
89 |
90 | @Override
91 | public int hashCode() {
92 | return Objects.hash(success, errorCode, errorDescription, content);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/ProcessReportOperationAborted.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import static org.junit.Assert.assertEquals;
26 | import static org.junit.Assert.assertNotNull;
27 |
28 | import com.ca.codesv.codesv_aws_service.AppEnv;
29 | import com.ca.codesv.codesv_aws_service.ReportCreatorService;
30 | import com.ca.codesv.codesv_aws_service.ReportDraft;
31 | import com.ca.codesv.codesv_aws_service.ValidationResult;
32 | import com.ca.codesv.codesv_aws_service.ViewModelHolder;
33 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
34 | import com.ca.codesv.engine.junit4.VirtualServerRule;
35 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
36 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
37 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
38 | import org.junit.Rule;
39 | import org.junit.Test;
40 |
41 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
42 | public class ProcessReportOperationAborted extends BaseTest {
43 |
44 | @Rule
45 | public VirtualServerRule vs = new VirtualServerRule();
46 |
47 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
48 |
49 | @Test
50 | public void processReportForm() throws Exception {
51 | store.useTransaction(S3CodeSvDemoBucketRepository.OPERATION_ABORTED_TXN);
52 |
53 | // Prepare view model which needs to be tested
54 | ViewModelHolder viewModelHolder = new ViewModelHolder();
55 |
56 | // Convert form POJO to ReportDraft POJO
57 | ReportDraft reportDraft = new ReportDraft(
58 | reportForm.getReportNameInput(),
59 | reportForm.getApplicationNameInput(),
60 | reportForm.getDescriptionTextArea(),
61 | new AppEnv(reportForm.getEnvNameInput(), reportForm.getEnvHostInput()));
62 |
63 | // Use creator service to process draft, upload to S3 as MyTest object to prepared bucket and get custom result validation
64 | ValidationResult validationResult =
65 | ReportCreatorService.getInstance().uploadReport(reportDraft, "MyTest4");
66 |
67 | assertNotNull("Validation result cannot be null.", validationResult);
68 |
69 | assertEquals(validationResult.getHttpCode(), 409);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/ProcessReportNoSuchBucketTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import static org.junit.Assert.assertEquals;
26 | import static org.junit.Assert.assertNotNull;
27 |
28 | import com.ca.codesv.codesv_aws_service.AppEnv;
29 | import com.ca.codesv.codesv_aws_service.ReportCreatorService;
30 | import com.ca.codesv.codesv_aws_service.ReportDraft;
31 | import com.ca.codesv.codesv_aws_service.UnknownValidationResultException;
32 | import com.ca.codesv.codesv_aws_service.ValidationResult;
33 | import com.ca.codesv.codesv_aws_service.ViewModelHolder;
34 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
35 | import com.ca.codesv.engine.junit4.VirtualServerRule;
36 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
37 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
38 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
39 | import org.junit.Rule;
40 | import org.junit.Test;
41 |
42 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
43 | public class ProcessReportNoSuchBucketTest extends BaseTest {
44 |
45 | @Rule
46 | public VirtualServerRule vs = new VirtualServerRule();
47 |
48 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
49 |
50 | @Test
51 | public void processReportForm() throws UnknownValidationResultException {
52 | store.useTransaction(S3CodeSvDemoBucketRepository.NON_EXISTING_BUCKET_TXN);
53 |
54 | // Prepare view model which needs to be tested
55 | ViewModelHolder viewModelHolder = new ViewModelHolder();
56 |
57 | // Convert form POJO to ReportDraft POJO
58 | ReportDraft reportDraft = new ReportDraft(
59 | reportForm.getReportNameInput(),
60 | reportForm.getApplicationNameInput(),
61 | reportForm.getDescriptionTextArea(),
62 | new AppEnv(reportForm.getEnvNameInput(), reportForm.getEnvHostInput()));
63 |
64 | // Use creator service to process draft, upload to S3 as MyTest object to prepared bucket and get custom result validation
65 | ValidationResult validationResult =
66 | ReportCreatorService.getInstance().uploadReport(reportDraft, "MyTest2");
67 |
68 | assertNotNull("Validation result cannot be null.", validationResult);
69 |
70 | assertEquals(validationResult.getHttpCode(), 404);
71 |
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/backup/ReportServiceParameterizedTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.backup;
24 |
25 | import com.ca.codesv.codesv_aws_service.AppEnv;
26 | import com.ca.codesv.codesv_aws_service.ReportDraft;
27 | import com.ca.codesv.codesv_aws_service.ReportService;
28 | import com.ca.codesv.codesv_aws_service.ReportUploadResult;
29 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
30 | import com.ca.codesv.engine.junit4.VirtualServerRule;
31 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
32 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
33 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
34 | import org.junit.BeforeClass;
35 | import org.junit.Rule;
36 | import org.junit.Test;
37 | import org.junit.runner.RunWith;
38 | import org.junit.runners.Parameterized;
39 |
40 | import java.util.Arrays;
41 | import java.util.Collection;
42 |
43 | import static org.junit.Assert.assertTrue;
44 |
45 | @RunWith(Parameterized.class)
46 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
47 | public class ReportServiceParameterizedTest {
48 |
49 | @Rule
50 | public VirtualServerRule vs = new VirtualServerRule();
51 |
52 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
53 |
54 | @Parameterized.Parameter
55 | public String transactionName;
56 |
57 | @BeforeClass
58 | public static void setUp() {
59 | System.setProperty("javax.net.ssl.trustStore",
60 | Thread.currentThread().getContextClassLoader().getResource("keystore.jks").getPath());
61 | System.setProperty("javax.net.ssl.trustStorePassword", "password");
62 | }
63 |
64 |
65 | @Parameterized.Parameters(name = "{index}: transactionName - {0}")
66 | public static Collection transactionName() {
67 | return Arrays.asList("successful report upload", "nonexisting bucket", "access denied");
68 | }
69 |
70 | @Test
71 | public void processReport() {
72 | store.useTransaction(transactionName);
73 | ReportDraft reportDraft = new ReportDraft("My testing report",
74 | "My Application",
75 | "Lorem ipsum",
76 | new AppEnv("dev_env", "localhost"));
77 |
78 | ReportUploadResult result = ReportService.getInstance().processReport(reportDraft);
79 |
80 | assertTrue(result.isSuccess() || !result.getErrorCode().isEmpty());
81 |
82 | }
83 | }
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/backup/ReportServiceCodeSvTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.backup;
24 |
25 | import com.ca.codesv.codesv_aws_service.AppEnv;
26 | import com.ca.codesv.codesv_aws_service.ReportDraft;
27 | import com.ca.codesv.codesv_aws_service.ReportService;
28 | import com.ca.codesv.codesv_aws_service.ReportUploadResult;
29 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
30 | import com.ca.codesv.engine.junit4.VirtualServerRule;
31 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
32 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
33 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
34 | import org.junit.*;
35 | import org.junit.runners.MethodSorters;
36 |
37 | import static org.junit.Assert.assertTrue;
38 |
39 | @FixMethodOrder(MethodSorters.NAME_ASCENDING)
40 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
41 | public class ReportServiceCodeSvTest {
42 |
43 | @Rule
44 | public VirtualServerRule vs = new VirtualServerRule();
45 |
46 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
47 |
48 | @Before
49 | public void setUp() {
50 | System.setProperty("javax.net.ssl.trustStore",
51 | Thread.currentThread().getContextClassLoader().getResource("keystore.jks").getPath());
52 | System.setProperty("javax.net.ssl.trustStorePassword", "password");
53 | }
54 |
55 | @Test
56 | public void processReportWithCodeSvOk() {
57 | store.useTransaction("successful report upload");
58 |
59 | ReportDraft reportDraft = new ReportDraft("My virtualized testing report",
60 | "My Application",
61 | "Lorem ipsum",
62 | new AppEnv("VS_env", "localhost"));
63 |
64 | ReportUploadResult result = ReportService.getInstance().processReport(reportDraft);
65 |
66 | assertTrue(result.isSuccess());
67 | }
68 |
69 |
70 | @Test
71 | public void processReportWithoutPermissions() {
72 | store.useTransaction("access denied");
73 |
74 | ReportDraft reportDraft = new ReportDraft("My virtualized testing report",
75 | "My Application",
76 | "Lorem ipsum",
77 | new AppEnv("VS_env", "localhost"));
78 |
79 | ReportUploadResult result = ReportService.getInstance().processReport(reportDraft);
80 |
81 | assertTrue("Return code doesnt match", result.getErrorCode().contentEquals("AccessDenied"));
82 | }
83 | }
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/ProcessReportSuccessTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import static org.junit.Assert.assertFalse;
26 |
27 | import com.ca.codesv.codesv_aws_service.AppEnv;
28 | import com.ca.codesv.codesv_aws_service.ReportCreatorService;
29 | import com.ca.codesv.codesv_aws_service.ReportDraft;
30 | import com.ca.codesv.codesv_aws_service.UnknownValidationResultException;
31 | import com.ca.codesv.codesv_aws_service.ValidationResult;
32 | import com.ca.codesv.codesv_aws_service.ViewModelHolder;
33 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
34 | import com.ca.codesv.engine.junit4.VirtualServerRule;
35 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
36 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
37 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
38 | import org.junit.Rule;
39 | import org.junit.Test;
40 |
41 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
42 | public class ProcessReportSuccessTest extends BaseTest {
43 |
44 | @Rule
45 | public VirtualServerRule vs = new VirtualServerRule();
46 |
47 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
48 |
49 | @Test
50 | public void processReportForm() throws UnknownValidationResultException {
51 | store.useTransaction(S3CodeSvDemoBucketRepository.SUCCESSFUL_REPORT_UPLOAD_TXN);
52 |
53 | // Prepare view model which needs to be tested
54 | ViewModelHolder viewModelHolder = new ViewModelHolder();
55 |
56 | // Convert form POJO to ReportDraft POJO
57 | ReportDraft reportDraft = new ReportDraft(
58 | reportForm.getReportNameInput(),
59 | reportForm.getApplicationNameInput(),
60 | reportForm.getDescriptionTextArea(),
61 | new AppEnv(reportForm.getEnvNameInput(), reportForm.getEnvHostInput()));
62 |
63 | // Use creator service to process draft, upload to S3 as MyTest object to prepared bucket and get custom result validation
64 | ValidationResult validationResult =
65 | ReportCreatorService.getInstance().uploadReport(reportDraft, "MyTest1");
66 |
67 | // Push validation result to view model holder to be able to return correct UI notifications to users
68 | viewModelHolder.addValidatedResult(validationResult);
69 |
70 | assertFalse("View attributes can not be empty.", viewModelHolder.getViewAttributes().isEmpty());
71 |
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/src/test/java/com/ca/codesv/example/repository/repositories/DefaultRepository.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example.repository.repositories;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forAnyRequest;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
28 |
29 | import com.ca.codesv.example.repository.pojo.ServiceResult;
30 | import com.ca.codesv.sdk.annotation.TransactionDefinition;
31 | import com.ca.codesv.sdk.annotation.VirtualServiceRepository;
32 | import com.google.gson.Gson;
33 |
34 | /**
35 | * Default repository.
36 | *
37 | * @author CA
38 | */
39 | @VirtualServiceRepository(serviceName = "Default service")
40 | public class DefaultRepository {
41 |
42 | public static final String SERVICE_URL = "http://www.carepositories.com";
43 |
44 | /**
45 | * Demo method.
46 | */
47 | @TransactionDefinition(name = "simpleResponse")
48 | public void virtualizedSimpleDefaultResponse() {
49 | ServiceResult result = new ServiceResult();
50 | result.setTags(TransactionDefinition.DEFAULT_TAG);
51 | result.setTxnName("simpleResponse");
52 |
53 | forGet(SERVICE_URL + "/simpleDefaultService").doReturn(
54 | okMessage()
55 | .withJsonBody(new Gson().toJson(result))
56 | );
57 | }
58 |
59 | /**
60 | * Demo method.
61 | */
62 | @TransactionDefinition(name = "anotherResponse", tags = "DEV")
63 | public void devResponse() {
64 | ServiceResult result = new ServiceResult();
65 | result.setTags("DEV");
66 | result.setTxnName("anotherResponse");
67 |
68 | forGet(SERVICE_URL + "/anotherService").doReturn(
69 | okMessage()
70 | .withJsonBody(new Gson().toJson(result))
71 | );
72 | }
73 |
74 | /**
75 | * Demo method.
76 | */
77 | @TransactionDefinition(name = "anotherResponse", tags = "QA")
78 | public void qaResponse() {
79 | ServiceResult result = new ServiceResult();
80 | result.setTags("QA");
81 | result.setTxnName("anotherResponse");
82 |
83 | forAnyRequest(SERVICE_URL + "/anotherService").doReturn(
84 | okMessage()
85 | .withJsonBody(new Gson().toJson(result))
86 | );
87 | }
88 |
89 | /**
90 | * Demo method.
91 | */
92 | @TransactionDefinition(name = "commonResponse")
93 | public void commonResponse() {
94 | ServiceResult result = new ServiceResult();
95 | result.setTxnName("commonResponse");
96 |
97 | forGet(SERVICE_URL + "/commonService").doReturn(
98 | okMessage()
99 | .withJsonBody(new Gson().toJson(result))
100 | );
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/main/java/com/ca/codesv/codesv_aws_service/ReportDraft.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service;
24 |
25 | import java.util.Date;
26 | import java.util.Objects;
27 |
28 | public class ReportDraft {
29 |
30 | private String reportName;
31 | private Date creationDate;
32 | private String applicationName;
33 | private String description;
34 | private AppEnv appEnv;
35 |
36 | public ReportDraft(String reportName) {
37 | this(reportName, "", "", new AppEnv("",""));
38 | }
39 |
40 | public ReportDraft(String reportName, String applicationName, String description, AppEnv appEnv) {
41 | this.reportName = reportName;
42 | this.applicationName = applicationName;
43 | this.description = description;
44 | this.appEnv = appEnv;
45 | this.creationDate = new Date();
46 | }
47 |
48 | public String getReportName() {
49 | return reportName;
50 | }
51 |
52 | public void setReportName(String reportName) {
53 | this.reportName = reportName;
54 | }
55 |
56 | public Date getCreationDate() {
57 | return creationDate;
58 | }
59 |
60 | public void setCreationDate(Date creationDate) {
61 | this.creationDate = creationDate;
62 | }
63 |
64 | public String getApplicationName() {
65 | return applicationName;
66 | }
67 |
68 | public void setApplicationName(String applicationName) {
69 | this.applicationName = applicationName;
70 | }
71 |
72 | public String getDescription() {
73 | return description;
74 | }
75 |
76 | public void setDescription(String description) {
77 | this.description = description;
78 | }
79 |
80 | public AppEnv getAppEnv() {
81 | return appEnv;
82 | }
83 |
84 | public void setAppEnv(AppEnv appEnv) {
85 | this.appEnv = appEnv;
86 | }
87 |
88 | @Override
89 | public boolean equals(Object o) {
90 | if (this == o) return true;
91 | if (o == null || getClass() != o.getClass()) return false;
92 | ReportDraft that = (ReportDraft) o;
93 | return Objects.equals(reportName, that.reportName) &&
94 | Objects.equals(creationDate, that.creationDate) &&
95 | Objects.equals(applicationName, that.applicationName) &&
96 | Objects.equals(description, that.description) &&
97 | Objects.equals(appEnv, that.appEnv);
98 | }
99 |
100 | @Override
101 | public int hashCode() {
102 | return Objects.hash(reportName, creationDate, applicationName, description, appEnv);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/UrlParameterExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 | import static junit.framework.TestCase.assertNotNull;
28 | import static junit.framework.TestCase.assertTrue;
29 | import static org.junit.Assert.assertEquals;
30 | import static org.junit.Assert.assertFalse;
31 |
32 | import com.ca.codesv.engine.junit4.VirtualServerRule;
33 | import java.io.BufferedReader;
34 | import java.io.InputStreamReader;
35 | import org.apache.http.HttpResponse;
36 | import org.apache.http.client.HttpClient;
37 | import org.apache.http.client.methods.HttpGet;
38 | import org.apache.http.impl.client.HttpClientBuilder;
39 | import org.junit.Rule;
40 | import org.junit.Test;
41 |
42 | /**
43 | * Example showing of using URL parameters.
44 | *
45 | * @author CA
46 | */
47 | public class UrlParameterExample {
48 |
49 | private static final String URL = "http://www.ca.com/portfolio/{year}";
50 |
51 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
52 | + "\"portfolio\": {\n"
53 | + " \"id\": \"1\",\n"
54 | + " \"year\": \"${attribute.year}\",\n"
55 | + " \"productNamesList\": [\n"
56 | + " \"CA Server Automation\",\n"
57 | + " \"CA Service Catalog\",\n"
58 | + " \"CA Service Desk Manager\",\n"
59 | + " \"CA Service Management\",\n"
60 | + " \"CA Service Operations Insight\",\n"
61 | + " \"CA Service Virtualization\"\n"
62 | + " ]\n"
63 | + "}}";
64 |
65 | @Rule
66 | public VirtualServerRule vs = new VirtualServerRule();
67 |
68 |
69 | @Test
70 | public void testAdvancedHttpUsage() throws Exception {
71 | forGet(URL)
72 | .doReturn(
73 | okMessage()
74 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
75 | );
76 |
77 | HttpClient client = HttpClientBuilder.create().build();
78 | HttpGet request = new HttpGet("http://www.ca.com/portfolio/2017");
79 | HttpResponse response;
80 |
81 | response = client.execute(request);
82 |
83 | BufferedReader rd = new BufferedReader(
84 | new InputStreamReader(response.getEntity().getContent()));
85 | StringBuffer result = new StringBuffer();
86 | String line;
87 | while ((line = rd.readLine()) != null) {
88 | result.append(line);
89 | }
90 |
91 | String body = result.toString();
92 |
93 | assertEquals(200, response.getStatusLine().getStatusCode());
94 | assertNotNull(body);
95 | assertTrue(body.contains("2017"));
96 | assertFalse(body.contains("${attribute.year}"));
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/codesv_aws_service/demo/ProcessReportParametrizedTest.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.codesv_aws_service.demo;
24 |
25 | import com.ca.codesv.codesv_aws_service.*;
26 | import com.ca.codesv.codesv_aws_service.repository.S3CodeSvDemoBucketRepository;
27 | import com.ca.codesv.engine.junit4.VirtualServerRule;
28 | import com.ca.codesv.model.ClassTransactionRepository;
29 | import com.ca.codesv.protocols.transaction.TxnRepoStore;
30 | import com.ca.codesv.protocols.transaction.TxnRepoStoreBuilder;
31 | import com.ca.codesv.sdk.annotation.TransactionClassRepository;
32 | import org.junit.Rule;
33 | import org.junit.Test;
34 | import org.junit.runner.RunWith;
35 | import org.junit.runners.Parameterized;
36 |
37 | import java.util.Collection;
38 | import java.util.List;
39 |
40 | import static org.junit.Assert.assertNotNull;
41 |
42 | @RunWith(Parameterized.class)
43 | @TransactionClassRepository(repoClasses = {S3CodeSvDemoBucketRepository.class})
44 | public class ProcessReportParametrizedTest extends BaseTest {
45 |
46 | @Rule
47 | public VirtualServerRule vs = new VirtualServerRule();
48 |
49 | private TxnRepoStore store = new TxnRepoStoreBuilder().build(this);
50 |
51 | @Parameterized.Parameter(0)
52 | public String transactionName;
53 |
54 | @Parameterized.Parameter(1)
55 | public String reportName;
56 |
57 | @Parameterized.Parameters(name = "{index}: transactionName - {0} for report {1}")
58 | public static Collection transactionName() {
59 | List transactionNames = ClassTransactionRepository.getTransactionNames(S3CodeSvDemoBucketRepository.class);
60 |
61 | return DemoUtils.prepareParameters(transactionNames);
62 | }
63 |
64 | @Test
65 | public void processReport() throws UnknownValidationResultException {
66 | store.useTransaction(transactionName);
67 |
68 | // Prepare view model which needs to be tested
69 | ViewModelHolder viewModelHolder = new ViewModelHolder();
70 |
71 | // Convert form POJO to ReportDraft POJO
72 | ReportDraft reportDraft = new ReportDraft(
73 | reportForm.getReportNameInput(),
74 | reportForm.getApplicationNameInput(),
75 | reportForm.getDescriptionTextArea(),
76 | new AppEnv(reportForm.getEnvNameInput(), reportForm.getEnvHostInput()));
77 |
78 | // Use creator service to process draft, upload to S3 as MyTest object to prepared bucket and get custom result validation
79 | ValidationResult validationResult =
80 | ReportCreatorService.getInstance().uploadReport(reportDraft, reportName);
81 |
82 | assertNotNull("Validation result cannot be null.", validationResult);
83 |
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/BasicAuthExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.contains;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forAnyRequest;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
28 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
29 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.unauthorizedMessage;
30 | import static junit.framework.TestCase.assertNotNull;
31 | import static org.hamcrest.core.Is.is;
32 | import static org.junit.Assert.assertEquals;
33 |
34 | import com.ca.codesv.engine.junit4.VirtualServerRule;
35 | import java.io.BufferedReader;
36 | import java.io.InputStreamReader;
37 | import org.apache.http.HttpResponse;
38 | import org.apache.http.auth.AuthScope;
39 | import org.apache.http.auth.UsernamePasswordCredentials;
40 | import org.apache.http.client.CredentialsProvider;
41 | import org.apache.http.client.HttpClient;
42 | import org.apache.http.client.methods.HttpGet;
43 | import org.apache.http.impl.client.BasicCredentialsProvider;
44 | import org.apache.http.impl.client.HttpClientBuilder;
45 | import org.junit.Rule;
46 | import org.junit.Test;
47 |
48 | /**
49 | * Example showing basic authorization.
50 | *
51 | * @author CA
52 | */
53 | public class BasicAuthExample {
54 |
55 | private static final String URL = "http://www.ca.com/portfolio";
56 |
57 | private static final String BODY = "Success";
58 |
59 | @Rule
60 | public VirtualServerRule vs = new VirtualServerRule();
61 |
62 |
63 | @Test
64 | public void testBasicAuth() throws Exception {
65 | // Our service with basic authorization
66 | forGet(URL)
67 | .matchesBasicAuthorization("commonUsername", "bestPasswordEver")
68 | .matchesBasicAuthorization(contains("common"), is("bestPasswordEver"))
69 | .doReturn(
70 | okMessage()
71 | .withStringBody(BODY)
72 | );
73 |
74 | // Simulate 401 with Authentication header
75 | forAnyRequest(URL)
76 | .doReturn(
77 | unauthorizedMessage()
78 | .withHeader("WWW-Authenticate", "Basic")
79 | );
80 |
81 | CredentialsProvider provider = new BasicCredentialsProvider();
82 | UsernamePasswordCredentials credentials
83 | = new UsernamePasswordCredentials("commonUsername", "bestPasswordEver");
84 | provider.setCredentials(AuthScope.ANY, credentials);
85 |
86 | HttpClient client = HttpClientBuilder.create()
87 | .setDefaultCredentialsProvider(provider)
88 | .build();
89 |
90 | HttpGet request = new HttpGet(URL);
91 | HttpResponse response = client.execute(request);
92 |
93 | BufferedReader reader = new BufferedReader(
94 | new InputStreamReader(response.getEntity().getContent()));
95 | StringBuffer result = new StringBuffer();
96 | String line;
97 | while ((line = reader.readLine()) != null) {
98 | result.append(line);
99 | }
100 |
101 | String body = result.toString();
102 | assertEquals(200, response.getStatusLine().getStatusCode());
103 | assertNotNull(body);
104 | assertEquals(BODY, body);
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/AdvancedMatchingExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.contains;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.isEqualIgnoringCaseTo;
28 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
29 | import static junit.framework.TestCase.assertNotNull;
30 | import static junit.framework.TestCase.assertTrue;
31 | import static org.junit.Assert.assertEquals;
32 | import static org.junit.Assert.assertFalse;
33 |
34 | import com.ca.codesv.engine.junit4.VirtualServerRule;
35 | import java.io.BufferedReader;
36 | import java.io.InputStreamReader;
37 | import org.apache.http.HttpResponse;
38 | import org.apache.http.client.HttpClient;
39 | import org.apache.http.client.methods.HttpGet;
40 | import org.apache.http.impl.client.HttpClientBuilder;
41 | import org.junit.Rule;
42 | import org.junit.Test;
43 |
44 | /**
45 | * Example showing advanced matching.
46 | *
47 | * @author CA
48 | */
49 | public class AdvancedMatchingExample {
50 |
51 | private static final String URL = "http://www.ca.com/portfolio?year=2016&tokenQuery=X4sPhj15WQE";
52 |
53 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
54 | + "\"portfolio\": {\n"
55 | + " \"id\": \"1\",\n"
56 | + " \"year\": \"${argument.year}\",\n"
57 | + " \"productNamesList\": [\n"
58 | + " \"CA Server Automation\",\n"
59 | + " \"CA Service Catalog\",\n"
60 | + " \"CA Service Desk Manager\",\n"
61 | + " \"CA Service Management\",\n"
62 | + " \"CA Service Operations Insight\",\n"
63 | + " \"CA Service Virtualization\"\n"
64 | + " ]\n"
65 | + "}}";
66 |
67 | @Rule
68 | public VirtualServerRule vs = new VirtualServerRule();
69 |
70 |
71 | @Test
72 | public void testAdvancedHttpUsage() throws Exception {
73 | forGet(URL)
74 | .matchesHeader("Custom-Header", "CustomValue")
75 | .matchesHeader("Accept-Language", contains("us"))
76 | .matchesQuery("tokenQuery", isEqualIgnoringCaseTo("x4sphj15wqe"))
77 | .matchesQuery("year", "2016")
78 | .doReturn(
79 | okMessage()
80 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
81 | .enableMagicStrings()
82 | );
83 |
84 | HttpClient client = HttpClientBuilder.create().build();
85 | HttpGet request = new HttpGet(URL);
86 | request.addHeader("Accept-Language", "en_us");
87 | request.addHeader("Custom-Header", "CustomValue");
88 |
89 | HttpResponse response = client.execute(request);
90 |
91 | BufferedReader reader = new BufferedReader(
92 | new InputStreamReader(response.getEntity().getContent()));
93 | StringBuffer result = new StringBuffer();
94 | String line;
95 | while ((line = reader.readLine()) != null) {
96 | result.append(line);
97 | }
98 |
99 | String body = result.toString();
100 |
101 | assertEquals(200, response.getStatusLine().getStatusCode());
102 | assertNotNull(body);
103 | assertTrue(body.contains("2016"));
104 | assertFalse(body.contains("${argument.year}"));
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/TemplateReferenceExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.api.matchers.GenericMatchers.matchesTemplate;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forPost;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
28 | import static junit.framework.TestCase.assertNotNull;
29 | import static org.junit.Assert.assertEquals;
30 |
31 | import com.ca.codesv.engine.junit4.VirtualServerRule;
32 | import java.io.BufferedReader;
33 | import java.io.InputStreamReader;
34 | import org.apache.http.HttpResponse;
35 | import org.apache.http.client.HttpClient;
36 | import org.apache.http.client.methods.HttpPost;
37 | import org.apache.http.entity.StringEntity;
38 | import org.apache.http.impl.client.HttpClientBuilder;
39 | import org.junit.Rule;
40 | import org.junit.Test;
41 |
42 | /**
43 | * Example showing usage of template matcher.
44 | *
45 | * @author CA
46 | */
47 | public class TemplateReferenceExample {
48 |
49 | private static final String BASE_URL = "http://www.ca.com/portfolio";
50 |
51 | private static final String TEMPLATE = "Hello, {computer}. Do you read me, {computer2}?;"
52 | + "Affirmative, {user}. I read you.;"
53 | + "Open the pod bay doors! {plead}!";
54 |
55 | private static final String TEXT = "Hello, HAL. Do you read me, HAL?;"
56 | + "Affirmative, Dave. I read you.;"
57 | + "Open the pod bay doors! PLEASE!";
58 |
59 | private static final String REFERENCE =
60 | "Hello, ${template.computer}. Do you read me, ${template.computer2}?;"
61 | + "Affirmative, ${template.user}. I read you.;"
62 | + "Open the pod bay doors! ${template.plead}!";
63 |
64 | @Rule
65 | public VirtualServerRule vs = new VirtualServerRule();
66 |
67 | @Test
68 | public void testTemplateMagicString() throws Exception {
69 | forPost(BASE_URL)
70 | .matchesHeader("Language", matchesTemplate("Language of Text: {language}"))
71 | .matchesBody(matchesTemplate(TEMPLATE))
72 | .doReturn(
73 | okMessage()
74 | .withStringBody(REFERENCE)
75 | .withHeader("Language", "${template.language}")
76 | // By default magic strings are disabled
77 | .enableMagicStrings()
78 | );
79 |
80 | HttpClient client = HttpClientBuilder.create().build();
81 | HttpPost request = new HttpPost(BASE_URL);
82 |
83 | // 2 headers with the same name and different values
84 | request.addHeader("Language", "Language of Text: en_us");
85 | request.setEntity(new StringEntity(TEXT));
86 |
87 | HttpResponse response = client.execute(request);
88 |
89 | BufferedReader reader = new BufferedReader(
90 | new InputStreamReader(response.getEntity().getContent()));
91 | StringBuffer result = new StringBuffer();
92 | String line;
93 | while ((line = reader.readLine()) != null) {
94 | result.append(line);
95 | }
96 |
97 | String body = result.toString();
98 |
99 | assertEquals(200, response.getStatusLine().getStatusCode());
100 | assertNotNull(body);
101 | assertEquals(TEXT, body);
102 | assertEquals("en_us", response.getFirstHeader("Language").getValue());
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/ExportExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.contains;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.isEqualIgnoringCaseTo;
28 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
29 | import static junit.framework.TestCase.assertNotNull;
30 | import static junit.framework.TestCase.assertTrue;
31 | import static org.junit.Assert.assertEquals;
32 | import static org.junit.Assert.assertFalse;
33 |
34 | import com.ca.codesv.engine.junit4.VirtualServerRule;
35 | import java.io.BufferedReader;
36 | import java.io.InputStreamReader;
37 | import org.apache.http.HttpResponse;
38 | import org.apache.http.client.HttpClient;
39 | import org.apache.http.client.methods.HttpGet;
40 | import org.apache.http.impl.client.HttpClientBuilder;
41 | import org.junit.After;
42 | import org.junit.Before;
43 | import org.junit.Rule;
44 | import org.junit.Test;
45 |
46 | /**
47 | * Example showing exporting.
48 | *
49 | * For created RR pairs check files in src/test/resources/generatedRRPairs/ folder.
50 | *
51 | * @author CA
52 | */
53 | public class ExportExample {
54 |
55 | private static final String URL = "http://www.ca.com/portfolio?year=2016&tokenQuery=X4sPhj15WQE";
56 |
57 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
58 | + "\"portfolio\": {\n"
59 | + " \"id\": \"1\",\n"
60 | + " \"year\": \"${argument.year}\",\n"
61 | + " \"productNamesList\": [\n"
62 | + " \"CA Server Automation\",\n"
63 | + " \"CA Service Catalog\",\n"
64 | + " \"CA Service Desk Manager\",\n"
65 | + " \"CA Service Management\",\n"
66 | + " \"CA Service Operations Insight\",\n"
67 | + " \"CA Service Virtualization\"\n"
68 | + " ]\n"
69 | + "}}";
70 |
71 | @Rule
72 | public VirtualServerRule vs = new VirtualServerRule();
73 |
74 |
75 | @Before
76 | public void beforeClass() {
77 | System.setProperty("codesv.export", "src/test/resources/generatedRRPairs/");
78 | }
79 |
80 | @After
81 | public void afterClass() {
82 | System.clearProperty("codesv.export");
83 | }
84 |
85 | @Test
86 | public void testExporting() throws Exception {
87 | forGet(URL)
88 | .matchesHeader("Custom-Header", "CustomValue")
89 | .matchesHeader("Accept-Language", contains("us"))
90 | .matchesQuery("tokenQuery", isEqualIgnoringCaseTo("x4sphj15wqe"))
91 | .matchesQuery("year", "2016")
92 | .doReturn(
93 | okMessage()
94 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
95 | .enableMagicStrings()
96 | );
97 |
98 | HttpClient client = HttpClientBuilder.create().build();
99 | HttpGet request = new HttpGet(URL);
100 | request.addHeader("Accept-Language", "en_us");
101 | request.addHeader("Custom-Header", "CustomValue");
102 |
103 | HttpResponse response = client.execute(request);
104 |
105 | BufferedReader reader = new BufferedReader(
106 | new InputStreamReader(response.getEntity().getContent()));
107 | StringBuffer result = new StringBuffer();
108 | String line;
109 | while ((line = reader.readLine()) != null) {
110 | result.append(line);
111 | }
112 |
113 | String body = result.toString();
114 |
115 | assertEquals(200, response.getStatusLine().getStatusCode());
116 | assertNotNull(body);
117 | assertTrue(body.contains("2016"));
118 | assertFalse(body.contains("${argument.year}"));
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/HttpsExample.java:
--------------------------------------------------------------------------------
1 |
2 | /******************************************************************************
3 | *
4 | * Copyright (c) 2017 CA. All rights reserved.
5 | *
6 | * This software and all information contained therein is confidential and
7 | * proprietary and shall not be duplicated, used, disclosed or disseminated
8 | * in any way except as authorized by the applicable license agreement,
9 | * without the express written permission of CA. All authorized reproductions
10 | * must be marked with this language.
11 | *
12 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
13 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
14 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
15 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
16 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
17 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
18 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
19 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
20 | * DAMAGE.
21 | *
22 | ******************************************************************************/
23 |
24 | package com.ca.codesv.example;
25 |
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
28 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.withSecureProtocol;
29 | import static org.junit.Assert.assertEquals;
30 |
31 | import com.ca.codesv.engine.junit4.VirtualServerRule;
32 | import com.ca.codesv.protocols.http.HttpConstants;
33 | import java.io.IOException;
34 | import java.io.InputStream;
35 | import java.net.URL;
36 | import java.security.SecureRandom;
37 | import java.security.cert.X509Certificate;
38 | import javax.net.ssl.HttpsURLConnection;
39 | import javax.net.ssl.SSLContext;
40 | import javax.net.ssl.TrustManager;
41 | import javax.net.ssl.X509TrustManager;
42 | import org.apache.commons.io.IOUtils;
43 | import org.junit.Before;
44 | import org.junit.Rule;
45 | import org.junit.Test;
46 |
47 | /**
48 | * Example showing HTTPs support.
49 | *
50 | * @author CA
51 | */
52 | public class HttpsExample {
53 |
54 | private static final String KEYSTORE_PATH = HttpsExample.class.getClassLoader()
55 | .getResource("ssl/keystore.jks").getPath();
56 | private static final String KEYSTORE_PASSWORD = "password";
57 | private static final String BODY_PLAIN_TEXT = "Success";
58 | private static final String BASE_URL_SSL = "https://localhost:8090/";
59 | private static final int HTTP_STATUS_OK_NUMB = 200;
60 |
61 | @Rule
62 | public VirtualServerRule vs = new VirtualServerRule();
63 |
64 | private TrustManager[] trustAllCerts;
65 | private SSLContext sslContext;
66 |
67 | /**
68 | * Preparing to trust everything with common name localhost.
69 | */
70 | @Before
71 | public void setUp() throws Exception {
72 | // using own trust manager
73 | trustAllCerts = new TrustManager[]{
74 | new X509TrustManager() {
75 | public java.security.cert.X509Certificate[] getAcceptedIssuers() {
76 | return new X509Certificate[0];
77 | }
78 |
79 | public void checkClientTrusted(
80 | java.security.cert.X509Certificate[] certs, String authType) {
81 | }
82 |
83 | public void checkServerTrusted(
84 | java.security.cert.X509Certificate[] certs, String authType) {
85 | if (certs.length != 1 || !certs[0].getIssuerX500Principal().getName()
86 | .contains("CN=localhost")) {
87 | throw new SecurityException("Invalid certificate");
88 | }
89 | }
90 | }
91 | };
92 |
93 | sslContext = SSLContext.getInstance("TLS");
94 | sslContext.init(null, trustAllCerts, new SecureRandom());
95 | }
96 |
97 | @Test(timeout = 10000L)
98 | public void testHttpsConnection() throws IOException {
99 | forGet(BASE_URL_SSL)
100 | .usingHttps(
101 | withSecureProtocol("TLS")
102 | .keystorePath(KEYSTORE_PATH)
103 | .keystorePassword(KEYSTORE_PASSWORD)
104 | .keyPassword(KEYSTORE_PASSWORD))
105 | .doReturn(
106 | okMessage()
107 | .withStringBody(BODY_PLAIN_TEXT)
108 | .withContentType(HttpConstants.PLAIN_TEXT));
109 |
110 | URL u = new URL(BASE_URL_SSL);
111 | HttpsURLConnection connection = (HttpsURLConnection) u.openConnection();
112 | connection.setSSLSocketFactory(sslContext.getSocketFactory());
113 | assertEquals(HTTP_STATUS_OK_NUMB, connection.getResponseCode());
114 | assertEquals(BODY_PLAIN_TEXT,
115 | IOUtils.toString((InputStream) connection.getContent()));
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/MagicStringExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.isEqualIgnoringCaseTo;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
28 | import static junit.framework.TestCase.assertNotNull;
29 | import static junit.framework.TestCase.assertTrue;
30 | import static org.hamcrest.Matchers.is;
31 | import static org.junit.Assert.assertEquals;
32 | import static org.junit.Assert.assertFalse;
33 |
34 | import com.ca.codesv.engine.junit4.VirtualServerRule;
35 | import java.io.BufferedReader;
36 | import java.io.InputStreamReader;
37 | import org.apache.http.HttpResponse;
38 | import org.apache.http.client.HttpClient;
39 | import org.apache.http.client.methods.HttpGet;
40 | import org.apache.http.impl.client.HttpClientBuilder;
41 | import org.junit.Rule;
42 | import org.junit.Test;
43 |
44 | /**
45 | * Example showing magic strings possibilities.
46 | *
47 | * @author CA
48 | */
49 | public class MagicStringExample {
50 |
51 | private static final String BASE_URL = "http://www.ca.com/portfolio";
52 | private static final String QUERY = "?year=2016&tokenQuery=X4sPhj15WQE";
53 |
54 | // This will be create this URL- > http://www.ca.com/portfolio/{id}?year=2016&tokenQuery=X4sPhj15WQE
55 | private static final String URL = BASE_URL + "/{id}" + QUERY;
56 |
57 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
58 | + "\"portfolio\": {\n"
59 | + " \"id\": \"${attribute.id}\",\n"
60 | + " \"year\": \"${argument.year}\",\n"
61 | + " \"language\": \"${metadata.Language}\",\n"
62 | + " \"productNamesList\": [\n"
63 | + " \"CA Server Automation\",\n"
64 | + " \"CA Service Catalog\",\n"
65 | + " \"CA Service Desk Manager\",\n"
66 | + " \"CA Service Management\",\n"
67 | + " \"CA Service Operations Insight\",\n"
68 | + " \"CA Service Virtualization\"\n"
69 | + " ]\n"
70 | + "}}";
71 |
72 | @Rule
73 | public VirtualServerRule vs = new VirtualServerRule();
74 |
75 | @Test
76 | public void testMagicString() throws Exception {
77 | forGet(URL)
78 | .matchesHeader("Language", is("en_us"))
79 | .matchesQuery("tokenQuery", isEqualIgnoringCaseTo("x4sphj15wqe"))
80 | .matchesQuery("year", "2016")
81 | .doReturn(
82 | okMessage()
83 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
84 | );
85 |
86 | HttpClient client = HttpClientBuilder.create().build();
87 | HttpGet request = new HttpGet(BASE_URL + "/1" + QUERY);
88 |
89 | // 2 headers with the same name and different values
90 | request.addHeader("Language", "en_us");
91 | request.addHeader("Language", "en_uk");
92 |
93 | HttpResponse response = client.execute(request);
94 |
95 | BufferedReader reader = new BufferedReader(
96 | new InputStreamReader(response.getEntity().getContent()));
97 | StringBuffer result = new StringBuffer();
98 | String line;
99 | while ((line = reader.readLine()) != null) {
100 | result.append(line);
101 | }
102 |
103 | String body = result.toString().replaceAll("\\s+", "");
104 |
105 | assertEquals(200, response.getStatusLine().getStatusCode());
106 | assertNotNull(body);
107 |
108 | assertTrue(body.contains("\"year\":\"2016\""));
109 | assertFalse(body.contains("${argument.year}"));
110 |
111 | assertTrue(body.contains("\"id\":\"1\""));
112 | assertFalse(body.contains("${attribute.id}"));
113 |
114 | // Only the first header value will be replace
115 | assertTrue(body.contains("\"language\":\"en_us\""));
116 | assertFalse(body.contains("${metadata.Language}"));
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/src/test/java/com/ca/codesv/model/ClassTransactionRepository.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2018 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.model;
24 |
25 | import com.ca.codesv.sdk.annotation.TransactionDefinition;
26 |
27 | import java.lang.annotation.Annotation;
28 | import java.lang.reflect.InvocationTargetException;
29 | import java.lang.reflect.Method;
30 | import java.util.ArrayList;
31 | import java.util.Arrays;
32 | import java.util.List;
33 | import java.util.stream.Collectors;
34 |
35 | /**
36 | * Defines common functionality for Class transaction repositories.
37 | *
38 | * Due to the static nature of class repositories, this is rather "utility" class than real base class of class repositories.
39 | */
40 | public abstract class ClassTransactionRepository {
41 |
42 | private static final String NAME_FIELD = "name";
43 | private static final String TAGS_FIELD = "tags";
44 |
45 | /**
46 | * Returns names of defined transactions for a given Class transaction repository.
47 | *
48 | * In case no transactions are defined, returns an empty list.
49 | *
50 | * @param repository transaction repository class
51 | * @return list of transaction names defined in repository
52 | */
53 | public static final List getTransactionNames(Class extends ClassTransactionRepository> repository) {
54 | List annotations = getDeclaredTransactionAnnotations(repository);
55 |
56 | List transactionNames = annotations.stream()
57 | .map(annotation -> getAnnotationParameterValue(annotation, String.class, NAME_FIELD))
58 | .collect(Collectors.toList());
59 |
60 | return transactionNames;
61 | }
62 |
63 | /**
64 | * Returns names of defined transactions for a given Class transaction repository and tag.
65 | *
66 | * In case no transactions are defined, returns an empty list.
67 | *
68 | * @param repository transaction repository class
69 | * @param tag tag for which to find transactions
70 | * @return list of transaction names defined in repository
71 | */
72 | public static final List getTransactionNamesByTag(Class extends ClassTransactionRepository> repository, String tag) {
73 | List annotations = getDeclaredTransactionAnnotations(repository);
74 |
75 | List transactionNames = annotations.stream()
76 | .filter(annotation -> Arrays.asList(getAnnotationParameterValue(annotation, String[].class, TAGS_FIELD)).contains(tag))
77 | .map(annotation -> getAnnotationParameterValue(annotation, String.class, NAME_FIELD)).collect(Collectors.toList());
78 |
79 | return transactionNames;
80 | }
81 |
82 | private static List getDeclaredTransactionAnnotations(Class extends ClassTransactionRepository> repository) {
83 | List annotations = new ArrayList();
84 |
85 | Method[] methods = repository.getDeclaredMethods();
86 |
87 | for (Method method : methods) {
88 | Annotation annotation = method.getAnnotation(TransactionDefinition.class);
89 | if (annotation != null) {
90 | annotations.add(annotation);
91 | }
92 | }
93 |
94 | return annotations;
95 | }
96 |
97 | private static T getAnnotationParameterValue(Annotation annotation, Class type, String parameterName) {
98 | T result = null;
99 | try {
100 | result = type.cast(annotation.annotationType().getMethod(parameterName).invoke(annotation));
101 | } catch (IllegalAccessException e) {
102 | e.printStackTrace();
103 | } catch (InvocationTargetException e) {
104 | e.printStackTrace();
105 | } catch (NoSuchMethodException e) {
106 | e.printStackTrace();
107 | }
108 | return result;
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/GetAndPostExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.aMessage;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forPost;
28 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
29 | import static junit.framework.TestCase.assertTrue;
30 | import static org.junit.Assert.assertEquals;
31 |
32 | import com.ca.codesv.engine.junit4.VirtualServerRule;
33 | import com.ca.codesv.protocols.http.HttpConstants;
34 | import java.io.BufferedReader;
35 | import java.io.IOException;
36 | import java.io.InputStreamReader;
37 | import java.util.ArrayList;
38 | import java.util.List;
39 | import org.apache.http.HttpResponse;
40 | import org.apache.http.client.HttpClient;
41 | import org.apache.http.client.entity.UrlEncodedFormEntity;
42 | import org.apache.http.client.methods.HttpGet;
43 | import org.apache.http.client.methods.HttpPost;
44 | import org.apache.http.impl.client.HttpClientBuilder;
45 | import org.apache.http.message.BasicNameValuePair;
46 | import org.junit.Rule;
47 | import org.junit.Test;
48 |
49 | /**
50 | * Example showing basic usage of SVasCode.
51 | *
52 | * @author CA
53 | */
54 | public class GetAndPostExample {
55 |
56 | private static final String URL = "http://www.ca.com/portfolio";
57 |
58 | private static String RESPONSE_BODY_GET = "Response body from virtualized service.";
59 | private static String RESPONSE_BODY_POST =
60 | "Response for id ${argument.id} with configured filter for ${argument.filter}.";
61 | private static int CUSTOM_STATUS_CODE = 258;
62 |
63 | @Rule
64 | public VirtualServerRule vs = new VirtualServerRule();
65 |
66 | @Test
67 | public void testSimpleHttpGetWithResponseCodeAndStringBody() throws IOException {
68 | forGet(URL).doReturn(
69 | aMessage(CUSTOM_STATUS_CODE)
70 | .withStringBody(RESPONSE_BODY_GET)
71 | );
72 |
73 | HttpGet httpGet = new HttpGet(URL);
74 | HttpClient httpClient = HttpClientBuilder.create().build();
75 | HttpResponse httpResponse = httpClient.execute(httpGet);
76 |
77 | assertEquals(CUSTOM_STATUS_CODE, httpResponse.getStatusLine().getStatusCode());
78 |
79 | BufferedReader reader = new BufferedReader(
80 | new InputStreamReader(httpResponse.getEntity().getContent()));
81 | String inputLine;
82 | StringBuffer response = new StringBuffer();
83 |
84 | while ((inputLine = reader.readLine()) != null) {
85 | response.append(inputLine);
86 | }
87 | reader.close();
88 |
89 | assertEquals(response.toString(), RESPONSE_BODY_GET);
90 | }
91 |
92 | @Test
93 | public void testSimpleHttpPost() throws IOException {
94 | forPost(URL).doReturn(
95 | okMessage()
96 | .withStringBody(RESPONSE_BODY_POST)
97 | .withContentType(HttpConstants.PLAIN_TEXT)
98 | .enableMagicStrings()
99 | );
100 |
101 | HttpPost httpPost = new HttpPost(URL);
102 | List parameters = new ArrayList(2);
103 | parameters.add(new BasicNameValuePair("id", "5"));
104 | parameters.add(new BasicNameValuePair("filter", "ALL"));
105 | httpPost.setEntity(new UrlEncodedFormEntity(parameters));
106 |
107 | HttpClient httpClient = HttpClientBuilder.create().build();
108 | HttpResponse httpResponse = httpClient.execute(httpPost);
109 |
110 | BufferedReader reader = new BufferedReader(
111 | new InputStreamReader(httpResponse.getEntity().getContent()));
112 | String inputLine;
113 | StringBuffer response = new StringBuffer();
114 |
115 | while ((inputLine = reader.readLine()) != null) {
116 | response.append(inputLine);
117 | }
118 | reader.close();
119 |
120 | assertTrue(response.toString().contains("Response for id 5"));
121 | assertTrue(response.toString().contains("filter for ALL."));
122 | }
123 | }
124 |
125 |
126 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/CurrentMagicDateExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forGet;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 | import static junit.framework.TestCase.assertNotNull;
28 | import static junit.framework.TestCase.assertTrue;
29 | import static org.junit.Assert.assertEquals;
30 |
31 | import com.ca.codesv.engine.junit4.VirtualServerRule;
32 | import java.io.BufferedReader;
33 | import java.io.InputStreamReader;
34 | import java.time.LocalDateTime;
35 | import java.time.format.DateTimeFormatter;
36 | import org.apache.http.HttpResponse;
37 | import org.apache.http.client.HttpClient;
38 | import org.apache.http.client.methods.HttpGet;
39 | import org.apache.http.impl.client.HttpClientBuilder;
40 | import org.junit.Rule;
41 | import org.junit.Test;
42 |
43 | /**
44 | * Example showing magic dates possibilities of generating magic date based on current date/time.
45 | *
46 | * @author CA
47 | */
48 | public class CurrentMagicDateExample {
49 |
50 | private static final String URL = "http://www.ca.com/portfolio/";
51 |
52 | private static final String JSON_EXAMPLES_PORTFOLIO_CURRENT_DATE = "{"
53 | + "\"portfolio\": {\n"
54 | + " \"id\": \"1\",\n"
55 | + " \"dateOfRequest\": \"${currentDate:+7d:\"yyyy-MM-dd\"}\",\n"
56 | + " \"productNamesList\": [\n"
57 | + " \"CA Server Automation\",\n"
58 | + " \"CA Service Catalog\",\n"
59 | + " \"CA Service Desk Manager\",\n"
60 | + " \"CA Service Management\",\n"
61 | + " \"CA Service Operations Insight\",\n"
62 | + " \"CA Service Virtualization\"\n"
63 | + " ]\n"
64 | + "}}";
65 |
66 | @Rule
67 | public VirtualServerRule vs = new VirtualServerRule();
68 |
69 | @Test
70 | public void testCurrentDateMagicDate() throws Exception {
71 | forGet(URL)
72 | .doReturn(
73 | okMessage()
74 | // Format current date to ISO_LOCAL_DATE_TIME format (yyyy-MM-dd)
75 | .withHeader("lastRequest", "${currentDate:ISO_LOCAL_DATE_TIME}")
76 | // Create current date with offset minus 1 week and format it to default format (yyyy-MM-dd'T'HH:mm:ss.sssX)
77 | .withHeader("lastModification", "${currentDate:-1w}")
78 | // Create current date with offset minus 1 hour and format it to ISO_OFFSET_DATE_TIME format (yyyy-MM-dd'T'HH:mm:ssXXX)
79 | .withHeader("dateOfCreation", "${currentDate:-1h:ISO_OFFSET_DATE_TIME}")
80 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO_CURRENT_DATE)
81 | );
82 |
83 | HttpClient client = HttpClientBuilder.create().build();
84 | HttpGet request = new HttpGet(URL);
85 | request.addHeader("Language", "en_us");
86 |
87 | HttpResponse response = client.execute(request);
88 |
89 | BufferedReader reader = new BufferedReader(
90 | new InputStreamReader(response.getEntity().getContent()));
91 | StringBuffer result = new StringBuffer();
92 | String line;
93 | while ((line = reader.readLine()) != null) {
94 | result.append(line);
95 | }
96 |
97 | String body = result.toString().replaceAll("\\s+", "");
98 |
99 | assertEquals(200, response.getStatusLine().getStatusCode());
100 | assertNotNull(body);
101 |
102 | LocalDateTime nextWeek = LocalDateTime.now().plusDays(7);
103 | assertTrue(body.contains(nextWeek.format(DateTimeFormatter.ISO_DATE)));
104 |
105 | // Asserting time of the creation of the response is impossible, just check different formats and offsets
106 | System.out.println(
107 | "${currentDate:ISO_LOCAL_DATE_TIME} generated " + response.getFirstHeader("lastRequest")
108 | .getValue());
109 | System.out
110 | .println("${currentDate:-1w} generated " + response.getFirstHeader("lastModification")
111 | .getValue());
112 | System.out.println("${currentDate:-1h:ISO_OFFSET_DATE_TIME} generated " + response
113 | .getFirstHeader("dateOfCreation").getValue());
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/XmlExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.contains;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.matchesXPath;
27 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
28 | import static junit.framework.TestCase.assertNotNull;
29 | import static org.junit.Assert.assertEquals;
30 |
31 | import com.ca.codesv.engine.junit4.VirtualServerRule;
32 | import com.ca.codesv.protocols.http.fluent.HttpFluentInterface;
33 | import java.io.BufferedReader;
34 | import java.io.IOException;
35 | import java.io.InputStreamReader;
36 | import java.io.StringReader;
37 | import javax.xml.parsers.DocumentBuilder;
38 | import javax.xml.parsers.DocumentBuilderFactory;
39 | import javax.xml.parsers.ParserConfigurationException;
40 | import org.apache.http.HttpResponse;
41 | import org.apache.http.client.HttpClient;
42 | import org.apache.http.client.methods.HttpGet;
43 | import org.apache.http.client.methods.HttpPost;
44 | import org.apache.http.entity.StringEntity;
45 | import org.apache.http.impl.client.HttpClientBuilder;
46 | import org.junit.Rule;
47 | import org.junit.Test;
48 | import org.w3c.dom.Document;
49 | import org.xml.sax.InputSource;
50 | import org.xml.sax.SAXException;
51 |
52 | /**
53 | * Example showing usage of XML payload.
54 | *
55 | * @author CA
56 | */
57 | public class XmlExample {
58 |
59 | private static final String URL = "http://www.ca.com/portfolio/xml";
60 |
61 | private static final String XML_BODY = "\n"
62 | + " 1\n"
63 | + " 2016\n"
64 | + " \n"
65 | + " CA Server Automation\n"
66 | + " CA Service Catalog\n"
67 | + " CA Service Desk Manager\n"
68 | + " CA Service Management\n"
69 | + " CA Service Operations Insight\n"
70 | + " CA Service Virtualization\n"
71 | + " \n"
72 | + " ";
73 |
74 | @Rule
75 | public VirtualServerRule vs = new VirtualServerRule();
76 |
77 | @Test
78 | public void testVirtualizedXmlBody() throws IOException, ParserConfigurationException, SAXException {
79 | HttpFluentInterface.forGet(URL)
80 | .doReturn(
81 | okMessage()
82 | .withXmlBody(XML_BODY)
83 | );
84 |
85 | HttpClient client = HttpClientBuilder.create().build();
86 | HttpGet request = new HttpGet(URL);
87 |
88 | HttpResponse response = client.execute(request);
89 |
90 | BufferedReader reader = new BufferedReader(
91 | new InputStreamReader(response.getEntity().getContent()));
92 | StringBuffer result = new StringBuffer();
93 | String line;
94 | while ((line = reader.readLine()) != null) {
95 | result.append(line);
96 | }
97 |
98 | String body = result.toString().replaceAll("\\s+", "");
99 |
100 | assertEquals(200, response.getStatusLine().getStatusCode());
101 | assertNotNull(body);
102 | assertEquals(XML_BODY.replaceAll("\\s+", ""), body);
103 |
104 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
105 | DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
106 |
107 | InputSource is = new InputSource(new StringReader(XML_BODY));
108 | Document doc = dBuilder.parse(is);
109 |
110 | doc.getDocumentElement().normalize();
111 |
112 | assertEquals("portfolio", doc.getDocumentElement().getNodeName());
113 |
114 | }
115 |
116 | @Test
117 | public void testXmlPath() throws Exception {
118 | HttpFluentInterface.forPost(URL)
119 | .matchesBodyPayload(matchesXPath("/portfolio"))
120 | .matchesBodyPayload(matchesXPath("/portfolio/year", contains("16")))
121 | .matchesBodyPayload(matchesXPath("/portfolio/id", "1"))
122 | .doReturn(
123 | okMessage()
124 | );
125 |
126 | HttpClient client = HttpClientBuilder.create().build();
127 | HttpPost request = new HttpPost(URL);
128 |
129 | request.setEntity(new StringEntity(XML_BODY));
130 |
131 | HttpResponse response;
132 | response = client.execute(request);
133 |
134 | assertEquals(200, response.getStatusLine().getStatusCode());
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/ImportExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.forPost;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 | import static junit.framework.TestCase.assertNotNull;
28 | import static org.junit.Assert.assertEquals;
29 |
30 | import com.ca.codesv.engine.junit4.VirtualServerRule;
31 | import java.io.BufferedReader;
32 | import java.io.InputStreamReader;
33 | import org.apache.http.HttpResponse;
34 | import org.apache.http.client.HttpClient;
35 | import org.apache.http.client.methods.HttpPost;
36 | import org.apache.http.entity.StringEntity;
37 | import org.apache.http.impl.client.HttpClientBuilder;
38 | import org.junit.Rule;
39 | import org.junit.Test;
40 |
41 | /**
42 | * Example showing possibility of using import functionality for matching requests.
43 | *
44 | * @author CA
45 | */
46 | public class ImportExample {
47 |
48 | private static final String URL = "http://www.ca.com/portfolio";
49 |
50 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
51 | + "\"portfolio\": {\n"
52 | + " \"id\": \"1\",\n"
53 | + " \"year\": \"2017\",\n"
54 | + " \"productNamesList\": [\n"
55 | + " \"CA Server Automation\",\n"
56 | + " \"CA Service Catalog\",\n"
57 | + " \"CA Service Desk Manager\",\n"
58 | + " \"CA Service Management\",\n"
59 | + " \"CA Service Operations Insight\",\n"
60 | + " \"CA Service Virtualization\"\n"
61 | + " ]\n"
62 | + "}}";
63 |
64 | @Rule
65 | public VirtualServerRule vs = new VirtualServerRule();
66 |
67 | @Test
68 | public void testImportOfRequestDifferentWay() throws Exception {
69 | forPost(URL)
70 | .matchesBodyFromFile(getClass().getClassLoader()
71 | .getResource("requests/txt_request.txt").getPath())
72 | .matchesHeaderFromFile("requests/txt_request.txt", "CustomHeader")
73 | .matchesHeaderFromFile("requests/txt_request.txt", "Accept-Language")
74 | .doReturn(
75 | okMessage()
76 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
77 | );
78 |
79 | HttpClient client = HttpClientBuilder.create().build();
80 | HttpPost request = new HttpPost(URL);
81 | /*
82 | Both header and values are the same as in referenced file
83 | */
84 | request.addHeader("Accept-Language", "zh-cn");
85 | request.addHeader("CustomHeader", "Header Value");
86 | request.setEntity(new StringEntity("Success"));
87 | HttpResponse response;
88 |
89 | response = client.execute(request);
90 | BufferedReader reader = new BufferedReader(
91 | new InputStreamReader(response.getEntity().getContent()));
92 | StringBuffer result = new StringBuffer();
93 | String line;
94 | while ((line = reader.readLine()) != null) {
95 | result.append(line);
96 | }
97 |
98 | String body = result.toString().replaceAll("\\s+", "");
99 |
100 | assertEquals(200, response.getStatusLine().getStatusCode());
101 | assertNotNull(body);
102 | assertEquals(JSON_EXAMPLES_PORTFOLIO.replaceAll("\\s+", ""), body);
103 | }
104 |
105 | @Test
106 | public void testImportOfRequest() throws Exception {
107 | forPost(URL)
108 | .matchesBodyFromFile("requests/txt_request.txt")
109 | .matchesHeaderFromFile("requests/txt_request.txt", "CustomHeader")
110 | .matchesHeaderFromFile("requests/txt_request.txt", "Accept-Language")
111 | .doReturn(
112 | okMessage()
113 | .withJsonBody(JSON_EXAMPLES_PORTFOLIO)
114 | );
115 |
116 | HttpClient client = HttpClientBuilder.create().build();
117 | HttpPost request = new HttpPost(URL);
118 | /*
119 | Both header and values are the same as in referenced file
120 | */
121 | request.addHeader("Accept-Language", "zh-cn");
122 | request.addHeader("CustomHeader", "Header Value");
123 | request.setEntity(new StringEntity("Success"));
124 |
125 | HttpResponse response = client.execute(request);
126 |
127 | BufferedReader reader = new BufferedReader(
128 | new InputStreamReader(response.getEntity().getContent()));
129 | StringBuffer result = new StringBuffer();
130 | String line;
131 | while ((line = reader.readLine()) != null) {
132 | result.append(line);
133 | }
134 |
135 | String body = result.toString().replaceAll("\\s+", "");
136 |
137 | assertEquals(200, response.getStatusLine().getStatusCode());
138 | assertNotNull(body);
139 | assertEquals(JSON_EXAMPLES_PORTFOLIO.replaceAll("\\s+", ""), body);
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/codesv-examples/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/codesv-examples/aws_s3_virtualized/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/codesv-examples/repositories-example/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/codesv-examples/virtualized-http-examples/src/test/java/com/ca/codesv/example/EncodingExample.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | *
3 | * Copyright (c) 2017 CA. All rights reserved.
4 | *
5 | * This software and all information contained therein is confidential and
6 | * proprietary and shall not be duplicated, used, disclosed or disseminated
7 | * in any way except as authorized by the applicable license agreement,
8 | * without the express written permission of CA. All authorized reproductions
9 | * must be marked with this language.
10 | *
11 | * EXCEPT AS SET FORTH IN THE APPLICABLE LICENSE AGREEMENT, TO THE EXTENT
12 | * PERMITTED BY APPLICABLE LAW, CA PROVIDES THIS SOFTWARE WITHOUT
13 | * WARRANTY OF ANY KIND, INCLUDING WITHOUT LIMITATION, ANY IMPLIED
14 | * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN
15 | * NO EVENT WILL CA BE LIABLE TO THE END USER OR ANY THIRD PARTY FOR ANY
16 | * LOSS OR DAMAGE, DIRECT OR INDIRECT, FROM THE USE OF THIS SOFTWARE,
17 | * INCLUDING WITHOUT LIMITATION, LOST PROFITS, BUSINESS INTERRUPTION,
18 | * GOODWILL, OR LOST DATA, EVEN IF CA IS EXPRESSLY ADVISED OF SUCH LOSS OR
19 | * DAMAGE.
20 | *
21 | ******************************************************************************/
22 |
23 | package com.ca.codesv.example;
24 |
25 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.matchesJsonPath;
26 | import static com.ca.codesv.protocols.http.fluent.HttpFluentInterface.okMessage;
27 | import static junit.framework.TestCase.assertNotNull;
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.assertNotEquals;
30 |
31 | import com.ca.codesv.engine.junit4.VirtualServerRule;
32 | import com.ca.codesv.protocols.http.fluent.HttpFluentInterface;
33 | import java.io.BufferedReader;
34 | import java.io.ByteArrayOutputStream;
35 | import java.io.IOException;
36 | import java.io.InputStreamReader;
37 | import java.util.zip.DeflaterOutputStream;
38 | import java.util.zip.GZIPInputStream;
39 | import java.util.zip.InflaterInputStream;
40 | import org.apache.commons.io.IOUtils;
41 | import org.apache.http.HttpResponse;
42 | import org.apache.http.client.HttpClient;
43 | import org.apache.http.client.methods.HttpPost;
44 | import org.apache.http.entity.ByteArrayEntity;
45 | import org.apache.http.impl.client.HttpClientBuilder;
46 | import org.junit.Rule;
47 | import org.junit.Test;
48 |
49 | /**
50 | * Example showing working with encodings.
51 | *
52 | * @author CA
53 | */
54 | public class EncodingExample {
55 |
56 | private static final String URL = "http://www.ca.com/portfolio";
57 |
58 | private static final String JSON_EXAMPLES_PORTFOLIO = "{"
59 | + "\"portfolio\": {\n"
60 | + " \"id\": \"1\",\n"
61 | + " \"year\": \"2017\",\n"
62 | + " \"productNamesList\": [\n"
63 | + " \"CA Server Automation\",\n"
64 | + " \"CA Service Catalog\",\n"
65 | + " \"CA Service Desk Manager\",\n"
66 | + " \"CA Service Management\",\n"
67 | + " \"CA Service Operations Insight\",\n"
68 | + " \"CA Service Virtualization\"\n"
69 | + " ]\n"
70 | + "}}";
71 |
72 | @Rule
73 | public VirtualServerRule vs = new VirtualServerRule();
74 |
75 | @Test
76 | public void testEncodings() throws IOException {
77 | HttpFluentInterface.forPost(URL)
78 | .matchesHeader("Content-Encoding", "deflate")
79 | .matchesBodyPayload(matchesJsonPath("$.portfolio.id"))
80 | .doReturn(
81 | okMessage()
82 | .withHeader("Content-Encoding", "gzip")
83 | .withBody(JSON_EXAMPLES_PORTFOLIO.getBytes())
84 | );
85 |
86 | // We need to disable automatic compression/decompression on client
87 | HttpClient client = HttpClientBuilder.create().disableContentCompression().build();
88 | HttpPost request = new HttpPost(URL);
89 |
90 | request.setEntity(new ByteArrayEntity(compressPayload(JSON_EXAMPLES_PORTFOLIO)));
91 | request.setHeader("Content-Type", "application/json");
92 | request.setHeader("Content-Encoding", "deflate");
93 |
94 | HttpResponse response = client.execute(request);
95 |
96 | BufferedReader reader = new BufferedReader(
97 | new InputStreamReader(response.getEntity().getContent()));
98 | StringBuffer result = new StringBuffer();
99 | String line;
100 | while ((line = reader.readLine()) != null) {
101 | result.append(line);
102 | }
103 |
104 | String body = result.toString().replaceAll("\\s+", "");
105 |
106 | assertEquals(200, response.getStatusLine().getStatusCode());
107 | assertNotNull(body);
108 | assertNotEquals(body, JSON_EXAMPLES_PORTFOLIO);
109 |
110 | // We will execute it one more time and now we will decompress the entity
111 | response = client.execute(request);
112 |
113 | body = decompressPayload(response);
114 |
115 | assertEquals(JSON_EXAMPLES_PORTFOLIO, body);
116 | }
117 |
118 | private byte[] compressPayload(String text) throws IOException {
119 | ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
120 | DeflaterOutputStream deflaterOutputStream = null;
121 | try {
122 | deflaterOutputStream = new DeflaterOutputStream(byteOutputStream);
123 | deflaterOutputStream.write(text.getBytes());
124 | deflaterOutputStream.finish();
125 | return byteOutputStream.toByteArray();
126 | } finally {
127 | deflaterOutputStream.close();
128 | byteOutputStream.close();
129 | }
130 | }
131 |
132 | private String decompressPayload(HttpResponse response) throws IOException {
133 | ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
134 | InflaterInputStream inflaterInputStream = new GZIPInputStream(
135 | response.getEntity().getContent());
136 | try {
137 | IOUtils.copy(inflaterInputStream, byteOutputStream);
138 | return new String(byteOutputStream.toByteArray());
139 | } finally {
140 | byteOutputStream.close();
141 | inflaterInputStream.close();
142 | }
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/codesv-examples/springboot-virtualized-soap-example/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn ( ) {
37 | echo "$*"
38 | }
39 |
40 | die ( ) {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save ( ) {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------