Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build.QA.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## build.properties
sf.username = michael+cidf14qa@codescience.com
sf.password = Demo1234P7GZKh3TeryIdilHN3xHorUL
sf.serverurl = https://login.salesforce.com
sf.maxPoll = 600

## settings to change in branch properties
## copy the build.master.properties to build.[branch].properties
sf.runallTests = true
sf.checkOnly = true
build.cmd = DeployAndRunAllTests
11 changes: 11 additions & 0 deletions build.TSO.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## build.properties
sf.username = michael+cidemotso@codescience.com
sf.password = Demo1234UG4uJHea35Jd5ReWH6mSSKSC
sf.serverurl = https://login.salesforce.com
sf.maxPoll = 600

## settings to change in branch properties
## copy the build.master.properties to build.[branch].properties
sf.runallTests = true
sf.checkOnly = true
build.cmd = DeployAndRunAllTests
11 changes: 11 additions & 0 deletions build.dev.branch1.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## build.properties
sf.username = michael+cidf14dev1@codescience.com
sf.password = Demo12341LXOl6SRW63IDnQct7aiI6Au
sf.serverurl = https://login.salesforce.com
sf.maxPoll = 600

## settings to change in branch properties
## copy the build.master.properties to build.[branch].properties
sf.runallTests = true
sf.checkOnly = true
build.cmd = DeployAndRunAllTests
1 change: 1 addition & 0 deletions dev.branch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

60 changes: 60 additions & 0 deletions src/classes/InventoryRealTime.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
global with sharing class InventoryRealTime {

webservice static Integer WS_UpdateInventory()
{
Inventory inventory = UpdateInventory();
if(inventory != null && inventory.RealTimeInventory != null) {
return inventory.RealTimeInventory.size();
}
return 0;
}

public static Inventory UpdateInventory()
{
HttpRequest req = new HttpRequest();
String endpoint = 'https://ci-df14-warehouse.firebaseio.com/Inventory.json';
req.setEndpoint(endpoint);
req.setMethod('GET');
Http h = new Http();
HttpResponse res = h.send(req);
if(res.getStatusCode() == 200){
if(res.getBody() != null && res.getBody() != '')
{
InventoryRealTime.Inventory inventory = (InventoryRealTime.Inventory)JSON.deserialize(res.getBody(), InventoryRealTime.Inventory.class);
system.debug('inventory : ' + inventory);
if(inventory!=null) {
List<Merchandise__c> merchandises = [SELECT Id, Name, Price__c, Quantity__c FROM Merchandise__c];
for(Merchandise__c merchandise : merchandises) {
for(Merchandise realTimeInventoryMerchanise : inventory.RealTimeInventory) {
system.debug('name :'+realTimeInventoryMerchanise.name);
if(merchandise.Name == realTimeInventoryMerchanise.name) {
merchandise.Price__c = realTimeInventoryMerchanise.price;
merchandise.Quantity__c = realTimeInventoryMerchanise.qty + 1;
}
}
}
update merchandises;
return inventory;
}
}
}
return null;
}

public class Inventory
{
public Merchandise[] RealTimeInventory;
}

public class Merchandise
{
public String name;
public Decimal price;
public Integer qty;
public Merchandise(String name, Decimal price, Integer qty){
this.name = name;
this.price = price;
this.qty = qty;
}
}
}
4 changes: 4 additions & 0 deletions src/classes/InventoryRealTime.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>28.0</apiVersion>
</ApexClass>
18 changes: 18 additions & 0 deletions src/classes/InventoryRealTimeMock.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class InventoryRealTimeMock {
public class UpdateInventoryResponse implements HttpCalloutMock{
public HTTPResponse respond(HTTPRequest req) {

HttpResponse res = new HttpResponse();
res.setHeader('Content-Type', 'application/json');
InventoryRealTime.Inventory inventory = new InventoryRealTime.Inventory();
inventory.RealTimeInventory = new InventoryRealTime.Merchandise[]{
new InventoryRealTime.Merchandise('Desktop', 599.99, 200),
new InventoryRealTime.Merchandise('Server', 1999.99, 300)
};
String responseJSON = JSON.serialize(inventory);
res.setBody(responseJSON);
res.setStatusCode(200);
return res;
}
}
}
4 changes: 4 additions & 0 deletions src/classes/InventoryRealTimeMock.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>28.0</apiVersion>
</ApexClass>
32 changes: 32 additions & 0 deletions src/classes/InventoryRealTimeTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@isTest
private class InventoryRealTimeTest {

@isTest static void test_UpdateInventory() {

Merchandise__c merchandise1 = AddMerchandise('Desktop', 599.99, 150);
Merchandise__c merchandise2 = AddMerchandise('Server', 1999.99, 200);

Test.startTest();
Test.setMock(HttpCalloutMock.class, new InventoryRealTimeMock.UpdateInventoryResponse());
InventoryRealTime.Inventory inventory = InventoryRealTime.UpdateInventory();
Test.stopTest();

//check if we have 2 products in inventory
system.assertEquals(inventory.RealTimeInventory.size(), 2);

//check if desktop was updated from 100 to 200
merchandise1 = GetMerchandiseByName('Desktop');
system.assertEquals(merchandise1.Quantity__c, inventory.RealTimeInventory[0].qty);
}

private static Merchandise__c AddMerchandise(String name, Decimal price, Integer qty){
Merchandise__c merchandise = new Merchandise__c(Name = name, Price__c = price, Quantity__c = qty);
insert merchandise;
return merchandise;
}

private static Merchandise__c GetMerchandiseByName(String name){
Merchandise__c merchandise = [SELECT Id, Name, Price__c, Quantity__c FROM Merchandise__c WHERE Name =: name];
return merchandise;
}
}
4 changes: 4 additions & 0 deletions src/classes/InventoryRealTimeTest.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>28.0</apiVersion>
</ApexClass>