CodeSVby CA Technologies

JUnit5 tests

Prerequisite httpclient-4.5.1.jar httpcore-4.4.4.jar commons-logging-1.2.jar gson-2.6.2.jar junit-jupiter-api-5.5.1.jar junit-jupiter-engine-5.5.1.jar This example uses CodeSV Junit5 VirtualServerResolver.class extension: JUnit5 example: @ExtendWith({VirtualServerResolver.class}) public class JUnit5CodeSVTest {   private static final String URL = “http://www.ca.com/portfolio”;   private static String RESPONSE_BODY_GET = “Response body from virtualized service.”;   private static int CUSTOM_STATUS_CODE = 258;   @Test   public void testSimpleHttpGetWithResponseCodeAndStringBody() throws IOException {     forGet(URL).doReturn(         aMessage(CUSTOM_STATUS_CODE)             .withStringBody(RESPONSE_BODY_GET)     );     HttpGet httpGet = new HttpGet(URL);     HttpClient httpClient = HttpClientBuilder.create().build();     HttpResponse httpResponse = httpClient.execute(httpGet);     assertEquals(CUSTOM_STATUS_CODE, httpResponse.getStatusLine().getStatusCode());     BufferedReader reader = new BufferedReader(         new InputStreamReader(httpResponse.getEntity().getContent()));     String inputLine;     StringBuffer response = new StringBuffer();     while ((inputLine = reader.readLine()) != null) {       response.append(inputLine);     }     reader.close();     assertEquals(response.toString(), RESPONSE_BODY_GET);   } }   

Read more

Refer to Blazemeter Mock Services transactions from code

From release 2.0.0, CodeSV provides functionality to use transactions defined in Blazemeter Mock Services in code to replace endpoint definitions. Usage To select transactions from Blazemeter Mock Services, should be declared TxnRepoStore object. Using useTransaction methods on store object user can specify criteria for filtering transactions.   @TransactionCloudRepository( workspaces = {“Default Workspace”}, apiKey = “…”, apiSecret = “…”, uri = “https://mock.blazemeter.com” ) public class CodeSVExampleTest { @Rule public VirtualServerRule virtualServerRule = new VirtualServerRule(); private TxnRepoStore store = new TxnRepoStoreBuilder().build(this); @Test public void codeSVExampleTest() { // virtualization based on Transactions from Repository store.useTransaction(“Example transaction”, “Default Service”); […]

Read more

Upload definitions to Blazemeter Mock Services

From release 2.0.0, CodeSV provides functionality for uploading endpoint definitions from code into Blazemeter Mock Services. Usage   @TransactionCloudRepository( workspaces = {“Default Workspace”}, apiKey = “…”, apiSecret = “…”, uri = “https://mock.blazemeter.com” ) public class CodeSVUploadExampleTest { @Rule public VirtualServerRule virtualServerRule = new VirtualServerRule(); private TxnRepoStore store = new TxnRepoStoreBuilder() .uploadDslToTransactionRepository(“Default Workspace”, “Default Service”).build(this); @Test public void codesvEUploadExampleTest() { forGet(“http://blazedemo.com/cities”) .doReturn(okMessage().withJsonBody(“…cities…”)); /* rest of the test */ } }  

Read more

Export definitions as file

From release 2.0.0, CodeSV provides functionality for exporting endpoint definitions from code into json transaction DSL file. This way developers using CodeSV can share the artifacts they created in code with other team members who can use and augment with Mock Services UI in Blazemeter Mock Services and spin up Mock Services hosting content imported from the […]

Read more

Class Repository

Prerequisite httpclient-4.5.1.jar httpcore-4.4.4.jar commons-logging-1.2.jar gson-2.6.2.jar From release 1.3.0, CodeSV provides functionality for defining class repositories containing predefined transactions. The main advantage of class repositories is the easy reuse of defined transactions between different tests and test classes in the same project. It also improves the combination of transactions and provides a single place to configure […]

Read more

Post Call Verification

Post Call Verification CodeSV supports post execution verification. This makes it possible to check how many times a specific request was invoked. It is possible to check all possible HTTP methods using verify methods for example; verifyGet(String url). It is also possible to create complex verification’s using matchers with which you can filter only specific request matching criteria. […]

Read more

Magic Strings

CodeSV supports generation of Magic Strings. Magic Strings are basically references to information/data from an incoming request that will be replaced with actual values in the response from the service. Magic strings functionality is turned ON by default and it is possible to disable it using disableMagicStrings() in the API as seen in the example: forGet(URL) .doReturn( okMessage() .withJsonBody(JSON_EXAMPLES_PORTFOLIO) […]

Read more

Magic Dates

CodeSV supports generation of magic dates. There are two possible magic dates, the first one is based on the current date that is computed when the response is created and the second one is based on information from the request. The functionality of magic dates is by default turned ON but it is possible to disable it […]

Read more

Encoding

Encoded Request and Response (Compressed Payloads) CodeSV supports encoded requests and can work with them effortlessly as shown in the example below. The only requirement for working with compressed payloads is to define the header Content-Enconding with an algorithm. At the moment supported algorithms are deflate and gzip. This means that even when a compressed payload is sent in the […]

Read more

Basic Authorization

Basic Authorization CodeSV supports matching basic authorization requests with predefined methods. It is possible to directly match the username and password or use different matchers to do more complex assertions. You can combine more than one virtualized service to create more complex use cases as shown in the example below. It is also important to […]

Read more