Updated code to use latest version

Modifed code sample to easy scenario
Deleted exisiting Code/files which are not required
This commit is contained in:
mokhan
2017-06-25 13:40:38 +05:30
parent 9e3e240a59
commit f8e8aa0fce
19 changed files with 302 additions and 381 deletions
@@ -1,52 +0,0 @@
package com.baeldung.spring.drools.service;
import com.baeldung.spring.drools.Application;
import com.baeldung.spring.drools.DroolConfiguration;
import com.baeldung.spring.drools.model.Applicant;
import com.baeldung.spring.drools.model.SuggestedRole;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static junit.framework.Assert.assertNull;
import static junit.framework.TestCase.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {DroolConfiguration.class})
public class ApplicantServiceIntegrationTest {
@Autowired
ApplicantService applicantService;
@Test
public void whenCriteriaMatching_ThenSuggestManagerRole(){
Applicant applicant=new Applicant("Davis",37,1600000.0,11);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertEquals("Manager",suggestedRole.getRole());
}
@Test
public void whenCriteriaMatching_ThenSuggestSeniorDeveloperRole(){
Applicant applicant=new Applicant("John",37,1200000.0,8);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertEquals("Senior developer",suggestedRole.getRole());
}
@Test
public void whenCriteriaMatching_ThenSuggestDeveloperRole(){
Applicant applicant=new Applicant("Davis",37,800000.0,3);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertEquals("Developer",suggestedRole.getRole());
}
@Test
public void whenCriteriaNotMatching_ThenNoRole(){
Applicant applicant=new Applicant("John",37,1200000.0,5);
SuggestedRole suggestedRole=new SuggestedRole();
applicantService.suggestARoleForApplicant(applicant,suggestedRole);
assertNull(suggestedRole.getRole());
}
}
@@ -1,34 +0,0 @@
package com.baeldung.spring.drools.service;
import com.baeldung.spring.drools.Application;
import com.baeldung.spring.drools.DroolConfiguration;
import com.baeldung.spring.drools.model.Product;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static junit.framework.TestCase.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {DroolConfiguration.class})
public class ProductServiceIntegrationTest {
@Autowired
ProductService productService;
@Test
public void whenProductTypeElectronic_ThenLabelBarcode(){
Product product=new Product("Microwave","Electronic");
product=productService.applyLabelToProduct(product);
assertEquals("BarCode",product.getLabel());
}
@Test
public void whenProductTypeBook_ThenLabelIsbn(){
Product product=new Product("AutoBiography","Book");
product=productService.applyLabelToProduct(product);
assertEquals("ISBN",product.getLabel());
}
}
@@ -0,0 +1,95 @@
package com.baeldung.spring.drools.service;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.spring.drools.model.TaxiRide;
import com.baeldung.spring.drools.model.Fare;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
public class TaxiFareCalculatorServiceTest {
ApplicationContext context = null;
TaxiFareCalculatorService taxiFareCalculatorService = null;
@Before
public void init() {
context = new AnnotationConfigApplicationContext(TaxiFareConfiguration.class);
taxiFareCalculatorService = (TaxiFareCalculatorService) context.getBean(TaxiFareCalculatorService.class);
}
@Test
public void testCalculateFareScenario1() {
TaxiRide taxiRide = new TaxiRide();
taxiRide.setbNightSurcharge(false);
taxiRide.setDistanceInMile(9L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(70), totalCharge);
}
@Test
public void testCalculateFareScenario2() {
TaxiRide taxiRide = new TaxiRide();
taxiRide.setbNightSurcharge(true);
taxiRide.setDistanceInMile(5L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(100), totalCharge);
}
@Test
public void testCalculateFareScenario3() {
TaxiRide taxiRide = new TaxiRide();
taxiRide.setbNightSurcharge(false);
taxiRide.setDistanceInMile(50L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(170), totalCharge);
}
@Test
public void testCalculateFareScenario4() {
TaxiRide taxiRide = new TaxiRide();
taxiRide.setbNightSurcharge(true);
taxiRide.setDistanceInMile(50L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(250), totalCharge);
}
@Test
public void testCalculateFareScenario5() {
TaxiRide taxiRide = new TaxiRide();
taxiRide.setbNightSurcharge(false);
taxiRide.setDistanceInMile(100L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(220), totalCharge);
}
@Test
public void testCalculateFareScenario6() {
TaxiRide taxiRide = new TaxiRide();
taxiRide.setbNightSurcharge(true);
taxiRide.setDistanceInMile(100L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(350), totalCharge);
}
}