-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
2,925 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package javatest; | ||
|
||
public class DependencyInjection { | ||
|
||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,3 @@ public static void main(String[] args){ | |
} | ||
|
||
} | ||
s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.