1515import java .util .ArrayList ;
1616import java .util .Arrays ;
1717import java .io .File ;
18+
19+ import org .apache .commons .collections4 .functors .FalsePredicate ;
1820import org .junit .Test ;
1921
2022import com .networknt .schema .ValidationMessage ;
2527import java .nio .file .DirectoryStream ;
2628import java .nio .file .Path ;
2729import java .nio .file .Paths ;
30+ import java .security .Timestamp ;
2831import java .nio .file .Files ;
2932import java .io .IOException ;
3033import java .net .MalformedURLException ;
@@ -1519,6 +1522,90 @@ public void testParentChain() {
15191522
15201523
15211524
1525+ }
1526+
1527+ @ Test
1528+ public void testWriteToPostman () {
1529+ Collection pmcTest = Collection .pmcFactory ();
1530+ Collection pmcTest2 = null ;
1531+ BodyElement body = null ;
1532+ RequestBody req = null ;
1533+ Response resp = null ;
1534+ String colName = new java .sql .Timestamp (System .currentTimeMillis ()).toString ();
1535+ //Test creating a new collection
1536+ try {
1537+
1538+ body = new BodyElement (enumRequestBodyMode .URLENCODED );
1539+ body .setFormdata ("x-field-1" , "value 1" , "This is value 1" );
1540+ body .setFormdata ("x-field-2" , "value 2" , "This is value 2" );
1541+ req = new RequestBody (enumHTTPRequestMethod .POST , "https://postman-echo.com/post" );
1542+ req .setBody (body );
1543+ resp = new Response ("NORMAL Urlencoded" , req , "OK" , 200 , "this is the expected response body" );
1544+ pmcTest .addRequest (req , "URLEncoded body" , resp );
1545+ pmcTest .setName ("UPSERT test " + colName );
1546+ }
1547+ catch (Exception eee ) {
1548+ eee .printStackTrace ();
1549+ assertTrue ("Exception creating test collection: " + eee .getMessage (), false );
1550+ }
1551+
1552+ try {
1553+ assertNull ("No postmanID before upsert: " , pmcTest .getPostmanID ());
1554+ pmcTest .upsertToPostman (null );
1555+ assertNotNull ("Postman ID successfully assigned: " , pmcTest .getPostmanID ());
1556+ }
1557+ catch (Exception e ) {
1558+ e .printStackTrace ();
1559+ assertTrue ("Exception upserting new collection to Postman: " + e .getMessage (), false );
1560+ }
1561+
1562+ //Upsert a collection to a workspace
1563+ try {
1564+
1565+ body = new BodyElement (enumRequestBodyMode .URLENCODED );
1566+ body .setFormdata ("x-field-1" , "value 1" , "This is value 1" );
1567+ body .setFormdata ("x-field-2" , "value 2" , "This is value 2" );
1568+ req = new RequestBody (enumHTTPRequestMethod .POST , "https://postman-echo.com/post" );
1569+ req .setBody (body );
1570+ resp = new Response ("NORMAL Urlencoded" , req , "OK" , 200 , "this is the expected response body" );
1571+ pmcTest .addRequest (req , "URLEncoded body" , resp );
1572+ pmcTest .setName ("UPSERT test to Workspace" + colName );
1573+ pmcTest .upsertToPostman (new PostmanID ("23889826-169dff8a-c684-4ccc-b8df-7ad436efda57" ));
1574+ }
1575+ catch (Exception eee ) {
1576+ eee .printStackTrace ();
1577+ assertTrue ("Exception creating test collection: " + eee .getMessage (), false );
1578+ }
1579+
1580+ //Fetch a known collection from Postman, change the name, then Upsert it
1581+ try {
1582+
1583+ pmcTest = Collection .pmcFactory (new PostmanID ("23889826-169dff8a-c684-4ccc-b8df-7ad436efda57" ));
1584+ String origName = pmcTest .getName ();
1585+ pmcTest .setName (origName + "- UPSERTED" );
1586+ pmcTest .upsertToPostman (null );
1587+ pmcTest = Collection .pmcFactory (new PostmanID ("23889826-169dff8a-c684-4ccc-b8df-7ad436efda57" ));
1588+ assertTrue (pmcTest .getName ().equals (origName + "- UPSERTED" ));
1589+ }
1590+ catch (Exception ee ) {
1591+ ee .printStackTrace ();
1592+ assertTrue ("Exception writing known collection: " + ee .getMessage (), false );
1593+ }
1594+
1595+
1596+ try {
1597+ //read in a collection with an ID
1598+ pmcTest = Collection .pmcFactory (new File (filePath + resourcePath + "/auth.postman_collection.json" ));
1599+ pmcTest .setName ("Auth renamed again " + new java .sql .Timestamp (System .currentTimeMillis ()));
1600+ pmcTest .upsertToPostman (null );
1601+ }
1602+ catch (Exception e )
1603+ {
1604+ assertTrue ("IOException: " + e .getMessage (), false );
1605+ }
1606+
1607+
1608+
15221609 }
15231610
15241611}
0 commit comments