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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/*
.out/
*.iml
target/
53 changes: 53 additions & 0 deletions WhatsApp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### WhatsAPP ###

Feature: Mute notification for
In order to test mute notification
As an user
I want to validate if we can mute the notifications.

Scenario: Register Whatsapp Number
Given App Whatsapp installed on the Mobile Phone
When the user click on the app icon
And the mobile number is valid
Then enter the mobile number on the app
And receive the authentication code

Scenario: Mute Notifications
Given A valid number with a channel group added before.
When the user click on chats tab
And click on the group chat
And the user click on the three dots right button
And click on Mute Notifications
Then enter the period of time to be muted
And click on OK button

Feature: Starred Messages
In order to test starred messages
As an user
I want to validate if we can see the starred messages.

Scenario: Starred Messages
Given App Whatsapp installed on the Mobile Phone and Registered
When the user click on chats tab
And click on the group chat
Then click on any message and hold the message
And click on the star icon

Scenario: See Starred Messages
Given A user with starred messages
When the user click on the three dots right button
And the user click on Starred Messages
Then see the messages starred before.

Feature: Search
In order to test search
As an user
I want to validate if we can get a list of words searched.

Scenario: Search
Given App Whatsapp installed on the Mobile Phone and Registered
When the user click on search button on the right corner
Then enter any word to search
And while typing the word it should appear on the list.


57 changes: 57 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>qa-recruting</groupId>
<artifactId>hsa</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-rules-core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-rules-mvel</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
64 changes: 64 additions & 0 deletions src/main/java/BasketFromConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import java.util.HashMap;

public class BasketFromConfig implements RulesPromotion{

private HashMap<String, Item> catalog;
private HashMap<String, Item> basketList;
private double total;

public BasketFromConfig(HashMap<String, Item> config) {
this.catalog = config;
basketList = new HashMap<>();
total = 0;
}

public void addItemToBasket(String productName){
if(!productName.equals("")){
Item item = catalog.get(productName);
if(basketList.get(productName) != null){
int aux = basketList.get(productName).getQuantity();
item.setQuantity(++aux);
basketList.put(productName,item);
}else{
int quantity = 1;
item.setQuantity(quantity);
basketList.put(productName,item);
}
}
}

public double checkTotal(){

total = 0;

basketList.forEach((name,item) -> {
int quantity = item.getQuantity();
if (item.getPromotions()!=null){
total = total + item.checkPromotion(quantity);
}else {
total = total + (quantity * item.getPrice());
}
});

return total;
}

public double price(String listOfItems){

basketList = new HashMap<>();
total = 0;

char[] arrayItems = listOfItems.toCharArray();

if (arrayItems.length != 0){
for (char sku:arrayItems) {
String productName = String.valueOf(sku);
addItemToBasket(productName);
}
}

return checkTotal();
}


}
142 changes: 142 additions & 0 deletions src/main/java/BasketFromRules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.mvel.MVELRule;
import org.jeasy.rules.mvel.MVELRuleFactory;
import org.jeasy.rules.support.YamlRuleDefinitionReader;

import java.io.FileReader;
import java.util.HashMap;


public class BasketFromRules implements RulesPromotion{

private HashMap<String,Item> basketList;
private double total;

private static Rules rules;

public static Rules getRulesYML() {

if (rules==null) {

MVELRuleFactory ruleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());

try {

rules = ruleFactory.createRules(new FileReader("src/test/resources/rules.yml"));

} catch (Exception e) {
e.printStackTrace();
}
}
return rules;
}
public static Rules getRulesAPI() {

if (rules==null) {

Rule itemA = new MVELRule()
.name("item A")
.description("1 item A for 50")
.when("item.getName() == 'A'")
.then("item.setPrice(item.getQuantity() * 50)");

Rule itemB = new MVELRule()
.name("item B")
.description("1 item B for 30")
.when("item.getName() == 'B'")
.then("item.setPrice(item.getQuantity() * 30)");

Rule itemC = new MVELRule()
.name("item C")
.description("1 item C for 20")
.when("item.getName() == 'C'")
.then("item.setPrice(item.getQuantity() * 20)");

Rule itemD = new MVELRule()
.name("item D")
.description("1 item D for 15")
.when("item.getName() == 'D'")
.then("item.setPrice(item.getQuantity() * 15)");

Rule promoA = new MVELRule()
.name("promo A")
.description("3 item A for 130")
.when("item.getName().equals('A') && item.getQuantity() / 3 >= 1")
.then("int q = item.getQuantity() / 3; item.setPrice(item.getPrice() - q * 20)");

Rule promoB = new MVELRule()
.name("promo B")
.description("2 item b for 45")
.when("item.getName().equals('B') && item.getQuantity() / 2 >= 1")
.then("int q = item.getQuantity() /2; item.setPrice(item.getPrice() - q * 15)");



rules = new Rules();
rules.register(itemA);
rules.register(itemB);
rules.register(itemC);
rules.register(itemD);
rules.register(promoA);
rules.register(promoB);
}
return rules;
}


public BasketFromRules(){

basketList = new HashMap<>();
total = 0;

}

private double calculatePrice(Item item){
RulesEngine rulesEngine = new DefaultRulesEngine();
Facts facts = new Facts();

facts.put("item", item);
rulesEngine.fire(rules, facts);

return item.getPrice();
}

public void addItemToBasket(String productName) {
if (productName.length() != 0){
Item scannedItem = new Item(productName);
Item item = basketList.get(scannedItem.getName());
if (item == null) {
scannedItem.setQuantity(1);
basketList.put(productName, scannedItem);
} else {
Integer quantity = item.getQuantity();
item.setQuantity(++quantity);
}
}

}

public double checkTotal(){
total = 0;
for (Item item : basketList.values()) {
total = total + calculatePrice(item);
}
return total;

}

public double price(String productName) {
basketList = new HashMap<>();
total = 0;

for (int i = 0; i < productName.length(); i++) {
addItemToBasket(productName.substring(i, i + 1));
}
return checkTotal();

}
}
58 changes: 58 additions & 0 deletions src/main/java/CatalogFromConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigObject;
import com.typesafe.config.ConfigValue;

import java.util.HashMap;

public class CatalogFromConfig {

private static Config defaultConfig;
private static HashMap<String,Item> catalog;

private static Config getConfig(String file) {
if (defaultConfig==null) {
defaultConfig = ConfigFactory.parseResources(file);

}
return defaultConfig;
}

public HashMap<String, Item> getListOfItems(String file){

if (catalog ==null) {

defaultConfig = getConfig(file);

final ConfigValue configItems = defaultConfig.getObject("products");

catalog = new HashMap<>(((ConfigObject) configItems).size());

((ConfigObject) configItems).keySet().forEach(pname -> {

ConfigObject productConfig = ((ConfigObject) configItems).toConfig().getObject(pname);
String productName = productConfig.get("productName").render().replaceAll("^\"|\"$", "");
String productPrice = productConfig.get("productPrice").render();

Item item;
Promotion promotion;

if (productConfig.containsKey("promotion")){
ConfigObject promotionConfig = (ConfigObject) productConfig.get("promotion");
String promoName = promotionConfig.get("promoName").render().replaceAll("^\"|\"$", "");
String promoNroItems = promotionConfig.get("promoNroItems").render();
String promoPrice = promotionConfig.get("promoPrice").render();
promotion = new Promotion(promoName,Integer.parseInt(promoNroItems),Double.parseDouble(promoPrice));
item = new Item(productName,Double.parseDouble(productPrice),promotion);
}else{
item = new Item(productName,Double.parseDouble(productPrice));
}

catalog.put(item.getName(),item);

});

}
return catalog;
}
}
Loading