Test Cases for Office API. (Reformatted Code)

This commit is contained in:
varunVNnayar
2014-12-11 13:49:29 +05:30
parent fa20a9ccb3
commit 632fac4d5b
@@ -23,6 +23,7 @@ import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification; import com.jayway.restassured.specification.ResponseSpecification;
import java.util.*; import java.util.*;
public class OfficeIntegrationsTest { public class OfficeIntegrationsTest {
private ResponseSpecification statusOkResponseSpec; private ResponseSpecification statusOkResponseSpec;
@@ -37,24 +38,24 @@ public class OfficeIntegrationsTest {
} }
@Test @Test
public void testCreateOffice() public void testCreateOffice() {
{
int random_array = {1997, 26, 12}; int random_array = {1997, 26, 12};
OfficeHelper oh = OfficeHelper // oh ---> Office Helper OfficeHelper oh = OfficeHelper // oh ---> Office Helper
.create(Utils.randomNameGenerator("", 5)) .create(Utils.randomNameGenerator("", 5))
.externalId(Utils.randomNameGenerator("offices-", 7)) .externalId(Utils.randomNameGenerator("offices-", 7))
.nameDecorated(Utils.randomNameGenerator("", 8)) .nameDecorated(Utils.randomNameGenerator("", 8))
.openingDate(random_array) .openingDate(random_array)
.hierarchy(".") .hierarchy(".")
.build(); .build();
String JsonData = oh.toJSON(); String JsonData = oh.toJSON();
final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec);
Assert.assertNotNull(officeID); Assert.assertNotNull(officeID);
} }
private Long createOffice(final String officeJSON, private Long createOffice(final String officeJSON,
final RequestSpecification requestSpec, final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) { final ResponseSpecification responseSpec) {
String officeId = String.valueOf(OfficeResourceHandler.createOffice(officeJSON, requestSpec, responseSpec)); String officeId = String.valueOf(OfficeResourceHandler.createOffice(officeJSON, requestSpec, responseSpec));
if (officeId.equals("null")) { if (officeId.equals("null")) {
// Invalid JSON data parameters // Invalid JSON data parameters
@@ -64,48 +65,48 @@ public class OfficeIntegrationsTest {
return new Long(officeId); return new Long(officeId);
@Test @Test
public void testCreateOfficeWithEmptyName() public void testCreateOfficeWithEmptyName ()
{ {
int random_array = {2000, 4, 8}; int random_array = {2000, 4, 8};
OfficeHelper oh = new OfficeHelper OfficeHelper oh = new OfficeHelper
.create(null) .create(null)
.externalId(Utils.randomNameGenerator("",5)) .externalId(Utils.randomNameGenerator("", 5))
.nameDecorated(Utils.randomNameGenerator("offices-", 6)) .nameDecorated(Utils.randomNameGenerator("offices-", 6))
.openingDate(random_array) .openingDate(random_array)
.hierarchy(".") .hierarchy(".")
.build(); .build();
String JsonData = oh.toJSON(); String JsonData = oh.toJSON();
final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); final Long officeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec);
Assert.assertNull(officeID); Assert.assertNull(officeID);
} }
@Test @Test
public void testCreateOfficeWithEmptyExternalId() public void testCreateOfficeWithEmptyExternalId ()
{ {
int random_array = {2005, 1, 1}; int random_array = {2005, 1, 1};
OfficeHelper oh = new OfficeHelper OfficeHelper oh = new OfficeHelper
.create(Utils.randomNameGenerator("", 3)) .create(Utils.randomNameGenerator("", 3))
.externalId(null) .externalId(null)
.nameDecorated(Utils.randomNameGenerator("offices-",5)) .nameDecorated(Utils.randomNameGenerator("offices-", 5))
.openingDate(random_array) .openingDate(random_array)
.hierarchy(".") .hierarchy(".")
.build(); .build();
String JsonData = oh.toJSON(); String JsonData = oh.toJSON();
final Long OfficeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); final Long OfficeID = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec);
Assert.assertNotNull(OfficeID); Assert.assertNotNull(OfficeID);
} }
@Test @Test
public void testCreateOfficeWithDuplicateName() public void testCreateOfficeWithDuplicateName ()
{ {
int random_array1 = {1998, 12, 10}; int random_array1 = {1998, 12, 10};
OfficeHelper oh1 = new OfficeHelper OfficeHelper oh1 = new OfficeHelper
.create(Utils.randomNameGenerator("", 7)) .create(Utils.randomNameGenerator("", 7))
.externalId(Utils.randomNameGenerator("Offices-", 4)) .externalId(Utils.randomNameGenerator("Offices-", 4))
.nameDecorated(Utils.randomNameGenerator("",10)) .nameDecorated(Utils.randomNameGenerator("", 10))
.openingDate(random_array1) .openingDate(random_array1)
.hierarchy(".") .hierarchy(".")
.build(); .build();
String JsonData = oh1.toJSON(); String JsonData = oh1.toJSON();
final Long OfficeID1 = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec); final Long OfficeID1 = createOfficeID(JsonData, this.requestSpec, this.statusOkResponseSpec);
Assert.assertNotNull(OfficeID); Assert.assertNotNull(OfficeID);
@@ -114,7 +115,7 @@ public class OfficeIntegrationsTest {
OfficeHelper oh2 = new OfficeHelper OfficeHelper oh2 = new OfficeHelper
.create(Utils.randomNameGenerator("", 7)) .create(Utils.randomNameGenerator("", 7))
.externalId(Utils.randomNameGenerator(oh.getName())) .externalId(Utils.randomNameGenerator(oh.getName()))
.nameDecorated(Utils.randomNameGenerator("",11)) .nameDecorated(Utils.randomNameGenerator("", 11))
.openingDate(random_array2) .openingDate(random_array2)
.hierarchy(".") .hierarchy(".")
.build(); .build();
@@ -126,13 +127,13 @@ public class OfficeIntegrationsTest {
} }
@Test @Test
public void testCreateOfficeWithDuplicateExternalId() public void testCreateOfficeWithDuplicateExternalId ()
{ {
int random_array1 = {2003, 2, 2}; int random_array1 = {2003, 2, 2};
OfficeHelper oh1 = new OfficeHelper OfficeHelper oh1 = new OfficeHelper
.create(Utils.randomNameGenerator("", 8)) .create(Utils.randomNameGenerator("", 8))
.externalId(oh1.getExternalId()) .externalId(oh1.getExternalId())
.nameDecorated(Utils.randomNameGenerator("",10)) .nameDecorated(Utils.randomNameGenerator("", 10))
.openingDate(random_array1) .openingDate(random_array1)
.hierarchy(".") .hierarchy(".")
.build(); .build();
@@ -145,7 +146,7 @@ public class OfficeIntegrationsTest {
OfficeHelper oh2 = new OfficeHelper OfficeHelper oh2 = new OfficeHelper
.create(Utils.randomNameGenerator("", 9)) .create(Utils.randomNameGenerator("", 9))
.externalId(Utils.randomNameGenerator("Offices-", 5)) .externalId(Utils.randomNameGenerator("Offices-", 5))
.nameDecorated(Utils.randomNameGenerator("",11)) .nameDecorated(Utils.randomNameGenerator("", 11))
.openingDate(random_array2) .openingDate(random_array2)
.hierarchy(".") .hierarchy(".")
.build(); .build();
@@ -159,12 +160,12 @@ public class OfficeIntegrationsTest {
} }
@Test @Test
public void testCreateOfficeWithEmptyOpeningDate() public void testCreateOfficeWithEmptyOpeningDate ()
{ {
OfficeHelper oh = new OfficeHelper OfficeHelper oh = new OfficeHelper
.create(Utils.randomNameGenerator("",9)) .create(Utils.randomNameGenerator("", 9))
.externalId(Utils.randomNameGenerator("Offices-",4)) .externalId(Utils.randomNameGenerator("Offices-", 4))
.nameDecorated(Utils.randomNameGenerator("",3)) .nameDecorated(Utils.randomNameGenerator("", 3))
.openingDate(null) .openingDate(null)
.hierarchy(".") .hierarchy(".")
.build(); .build();
@@ -175,7 +176,7 @@ public class OfficeIntegrationsTest {
} }
@Test @Test
public void testNameUnknowForNow() public void testNameUnknowForNow ()
{ {
OfficeHelper oh = new OfficeHelper OfficeHelper oh = new OfficeHelper
.create() .create()
@@ -187,5 +188,5 @@ public class OfficeIntegrationsTest {
} }
} }
} }