Skip to content

Commit

Permalink
change in automation code
Browse files Browse the repository at this point in the history
  • Loading branch information
vinod812 committed Jul 23, 2024
1 parent c620f78 commit 4c2832a
Show file tree
Hide file tree
Showing 74 changed files with 2,925 additions and 251 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="resource"/>
<classpathentry exported="true" kind="con" path="org.testng.TESTNG_CONTAINER"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
Expand Down
274 changes: 159 additions & 115 deletions extent-reports/extent-report.html

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>


<!-- JSON Schema Validator dependency -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>4.3.3</version>
</dependency>
</dependencies>
</project>
3 changes: 3 additions & 0 deletions resource/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,age,street,city,zipcode,phoneNumber1,phoneNumber2
John Doe,30,123 Main St,Anytown,12345,123-456-7890,987-654-3210
Jane Doe,25,456 Oak St,Anycity,67890,234-567-8901,876-543-2109
16 changes: 16 additions & 0 deletions resource/jsonvalidator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"role": {
"type": "string"
}
},
"required": ["id", "name", "role"]
}
12 changes: 12 additions & 0 deletions src/main/java/javatest/AbstractClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package javatest;

public abstract class AbstractClass {

public abstract void test();


public void newtest() {
System.out.println("hiiiiiiiiiii");
}

}
51 changes: 51 additions & 0 deletions src/main/java/javatest/ComparableTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package javatest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class ComparableTest implements Comparable<ComparableTest>{
private String name;
private int age;

public ComparableTest(String name, int age){
this.name=name;
this.age=age;
}

@Override
public int compareTo(ComparableTest other) {
return Integer.compare(this.age, other.age);
}
public String getName(){
return this.name;
}

public int getAge(){
return this.age1;
}


@Override
public String toString() {
return namehere + " (" + age1 + ")";
}

public static void main(String[] args) {

//ComparableTest ComparableTest=new ComparableTest();
List<ComparableTest> comparableTest=new ArrayList();
comparableTest.add(new ComparableTest("Vinod",43));
comparableTest.add(new ComparableTest("Arjun", 10));
comparableTest.add(new ComparableTest("Panchhi",13));
comparableTest.add(new ComparableTest("Sarita",33));

Collections.sort(comparableTest);

for(ComparableTest person: comparableTest){
System.out.println(person);
}


}
}
8 changes: 8 additions & 0 deletions src/main/java/javatest/DependencyInjection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package javatest;

public class DependencyInjection {

}



9 changes: 9 additions & 0 deletions src/main/java/javatest/FunctionalInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package javatest;

public interface FunctionalInterface {
void action();

default void method1(){
System.out.println("dDefault method");
}
}
10 changes: 10 additions & 0 deletions src/main/java/javatest/LamdaExpression.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package javatest;

public class LamdaExpression {

public static void main(String[] args) {
FunctionalInterface func=()->System.out.println("lamda");
func.action();
}

}
20 changes: 20 additions & 0 deletions src/main/java/javatest/TypecastWide.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package javatest;

public class TypecastWide {

public static void main(String[] args) {

//Widening is done automaticallu
int data=4;
System.out.println(data);
long longdata=data;
System.out.println(longdata);

//Narrowing code change is required
long dataLong=199;
int dataint=(int) dataLong;
System.out.println(dataLong);
System.out.println(dataint);

}
}
18 changes: 18 additions & 0 deletions src/main/java/javatest/UpcastDog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package javatest;
public class UpcastDog extends Upcasting {
@Override
public void makeSound() {
System.out.println("Dog bark");
}
public static void main(String[] args) {
UpcastDog updog=new UpcastDog();
//Upcasting
Upcasting Upcasting=updog;// upcasting
//Upcasting.makeSound();

//Downcasting
updog=(UpcastDog) Upcasting;
updog.makeSound();

}
}
6 changes: 6 additions & 0 deletions src/main/java/javatest/Upcasting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package javatest;
public class Upcasting {
public void makeSound() {
System.out.println("Animal Sounds");
}
}
4 changes: 2 additions & 2 deletions src/main/java/javatest/Wiremock.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Wiremock {

public static void main(String[] args) {
WireMockServer wiremockserver = new WireMockServer();
/* WireMockServer wiremockserver = new WireMockServer();
wiremockserver.start();
WireMock.configureFor("localhost", 8081);
// Stub a request
Expand All @@ -20,7 +20,7 @@ public static void main(String[] args) {
// Stop the WireMock server
//wireMockServer.stop();

*/

}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/javatest/singleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ public static void main(String[] args){
}

}
s
29 changes: 29 additions & 0 deletions src/main/java/resttest/CSVReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package resttest;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CSVReader {

public static List<Map<String, String>> readCSV(String filePath) throws IOException {
List<Map<String, String>> records = new ArrayList<>();

try (CSVParser csvParser = new CSVParser(new FileReader(filePath), CSVFormat.DEFAULT.withFirstRecordAsHeader())) {
for (CSVRecord csvRecord : csvParser) {
Map<String, String> record = new HashMap<>();
csvRecord.toMap().forEach(record::put);
records.add(record);
}
}

return records;
}
}
71 changes: 71 additions & 0 deletions src/main/java/resttest/Jsonpayloadstring.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package resttest;


import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import io.restassured.RestAssured;
import utility.ExtentReportListener;
import utility.RestAssuredLoggingFilter;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.aventstack.extentreports.Status;

public class Jsonpayloadstring {

private static WireMockServer wireMockServer;

@BeforeClass
public static void setup() throws InterruptedException {
wireMockServer = new WireMockServer(WireMockConfiguration.options().port(8081));
wireMockServer.start();
WireMock.configureFor("localhost", 8081);

WireMock.stubFor(post("/api/create")
.withRequestBody(equalToJson("{ \"name\": \"John Doe\" }"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"message\": \"Received: John Doe\" }")));

//Thread.sleep(10000);
}

@AfterClass
public static void teardown() {
// wireMockServer.stop();
}

@Test
public void testCreate() {
RestAssured.baseURI = "http://localhost";
RestAssured.port = 8081;

String jsonBody = "{\"name\":\"John Doe\"}";
ExtentReportListener.getTest().log(Status.INFO, "ChromeDriver initialized");

given()
.filter(new RestAssuredLoggingFilter())
.contentType("application/json")
.body(jsonBody)
.when()
.post("/api/create")
.then()
.statusCode(200)
.body("message", equalTo("Received: John Doe"));
ExtentReportListener.getTest().log(Status.PASS, "GET request successful and response validated");


}



}
45 changes: 45 additions & 0 deletions src/main/java/resttest/RestAssuredExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package resttest;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Map;

import org.testng.annotations.Test;

public class RestAssuredExample {

@Test
public void testcsv() {
try {
// Read CSV data

// Get the CSV file path from the resources directory
// URL resource = getClass().getClassLoader().getResource("C:\\data.csv");

/* if(resource == null) {
throw new IOException("File not found exceptoin ");
}*/

// String filepath=resource.getPath();
String filepath="C:\\data.csv";
// System.out.println(resource);
List<Map<String, String>> csvData = CSVReader.readCSV(filepath);

// Convert to JSON and send the request
RestAssured.given()
.contentType(ContentType.JSON)
.body(csvData)
.when()
.post("http://example.com/api/endpoint")
.then()
.statusCode(201);

} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit 4c2832a

Please sign in to comment.