227 lines
7.5 KiB
Java
227 lines
7.5 KiB
Java
package src.fr.test;
|
|
|
|
import java.util.Set;
|
|
import java.io.IOException;
|
|
import java.util.HashSet;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import src.fr.impl.*;
|
|
import src.fr.impl.Parts.*;
|
|
import src.fr.api.*;
|
|
|
|
public class test_V2 {
|
|
|
|
CategoryImpl engine = new CategoryImpl("Engine");
|
|
CategoryImpl transmission = new CategoryImpl("Transmission");
|
|
CategoryImpl exterior = new CategoryImpl("Exterior");
|
|
CategoryImpl interior = new CategoryImpl("Interior");
|
|
|
|
//PartType
|
|
PartType EG100= new PartTypeImpl("EG100",Engine.class, engine);
|
|
PartType EG133= new PartTypeImpl("EG133",Engine.class, engine);
|
|
PartType EG210= new PartTypeImpl("EG210",Engine.class, engine);
|
|
PartType ED110= new PartTypeImpl("ED110",Engine.class, engine);
|
|
PartType ED180= new PartTypeImpl("ED180",Engine.class, engine);
|
|
PartType EH120= new PartTypeImpl("EH120",Engine.class, engine);
|
|
|
|
PartType TM5= new PartTypeImpl("TM5", Transmission.class ,transmission);
|
|
PartType TM6= new PartTypeImpl("TM6", Transmission.class ,transmission);
|
|
PartType TA5= new PartTypeImpl("TA5", Transmission.class ,transmission);
|
|
PartType TS6= new PartTypeImpl("TS6", Transmission.class ,transmission);
|
|
PartType TSF7= new PartTypeImpl("TSF7", Transmission.class ,transmission);
|
|
PartType TC120= new PartTypeImpl("TC120", Transmission.class ,transmission);
|
|
|
|
PartType XC= new PartTypeImpl("XC", Exterior.class,exterior);
|
|
PartType XM= new PartTypeImpl("XM", Exterior.class,exterior);
|
|
PartType XS= new PartTypeImpl("XS", Exterior.class,exterior);
|
|
|
|
PartType IN= new PartTypeImpl("IN", Interior.class ,interior);
|
|
PartType IH= new PartTypeImpl("IH", Interior.class ,interior);
|
|
PartType IS= new PartTypeImpl("IS", Interior.class ,interior);
|
|
|
|
CompatibilityManager cm;
|
|
|
|
|
|
@BeforeEach
|
|
public void init(){
|
|
|
|
cm = new CompatibilityManagerImpl();
|
|
|
|
Set<PartType> EH120Requirement = new HashSet<PartType>();
|
|
EH120Requirement.add(TC120);
|
|
|
|
Set<PartType> TA5Incompatibilities = new HashSet<PartType>();
|
|
TA5Incompatibilities.add(EG100);
|
|
|
|
Set<PartType> TSF7Incompatibilities = new HashSet<PartType>();
|
|
TSF7Incompatibilities.add(EG100);
|
|
TSF7Incompatibilities.add(EG133);
|
|
TSF7Incompatibilities.add(ED110);
|
|
|
|
Set<PartType> TC120Requirement = new HashSet<PartType>();
|
|
TC120Requirement.add(EH120);
|
|
|
|
Set<PartType> XCIncompatibilities = new HashSet<PartType>();
|
|
XCIncompatibilities.add(EG210);
|
|
|
|
Set<PartType> XMIncompatibilities = new HashSet<PartType>();
|
|
XMIncompatibilities.add(EG100);
|
|
|
|
Set<PartType> XSIncompatibilities = new HashSet<PartType>();
|
|
XSIncompatibilities.add(EG100);
|
|
Set<PartType> XSRequirement = new HashSet<PartType>();
|
|
XSRequirement.add(IS);
|
|
|
|
Set<PartType> ISIncompatibilities = new HashSet<PartType>();
|
|
ISIncompatibilities.add(EG100);
|
|
ISIncompatibilities.add(TM5);
|
|
Set<PartType> ISRequirement = new HashSet<PartType>();
|
|
ISRequirement.add(XS);
|
|
|
|
cm.addRequirements(EH120, EH120Requirement);
|
|
cm.addIncompatibilities(TA5, TA5Incompatibilities);
|
|
cm.addIncompatibilities(TSF7, TSF7Incompatibilities);
|
|
cm.addRequirements(TC120, TC120Requirement);
|
|
cm.addIncompatibilities(XC, XCIncompatibilities);
|
|
cm.addIncompatibilities(XM, XMIncompatibilities);
|
|
cm.addIncompatibilities(XS, XSIncompatibilities);
|
|
cm.addRequirements(XS, XSRequirement);
|
|
cm.addIncompatibilities(IS, ISIncompatibilities);
|
|
cm.addRequirements(IS, ISRequirement);
|
|
|
|
}
|
|
|
|
@Test
|
|
public void test_NotProperty(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
assertEquals(config1.getPart(exterior).getProperty("color").get(), "white");
|
|
assertEquals(config1.getPart(interior).getProperty("color").get(), "black");
|
|
assertTrue(config1.isValid());
|
|
}
|
|
|
|
@Test
|
|
public void test_Property(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
config1.getPart(exterior).setProperty("color","red");
|
|
|
|
assertEquals(config1.getPart(exterior).getProperty("color").get(), "red");
|
|
assertTrue(config1.isValid());
|
|
}
|
|
|
|
@Test
|
|
public void test_NotCompatibleProperty(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
|
|
config1.getPart(exterior).setProperty("color","gsqgsdf");
|
|
|
|
assertEquals(config1.getPart(exterior).getProperty("color").get(), "gsqgsdf");
|
|
assertFalse(config1.isValid());
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
void test_Price(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
assertEquals(((PartImpl)config1.getPart(engine)).getPrice(), 25000);
|
|
}
|
|
|
|
@Test
|
|
void test_Config_Price(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
assertEquals(config1.getTotalPrice(), 52500);
|
|
}
|
|
|
|
@Test
|
|
void test_Config_Price_No_Complete(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
assertEquals(config1.getTotalPrice(), 40000);
|
|
}
|
|
|
|
@Test
|
|
void test_Config_Price_No_Valid(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG100);
|
|
config1.selectPart(TSF7);
|
|
assertFalse(config1.isValid());
|
|
assertEquals(config1.getTotalPrice(), -1);
|
|
}
|
|
|
|
@Test
|
|
void test_Config_Price_Empty_config(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
assertTrue(config1.isValid());
|
|
assertEquals(config1.getTotalPrice(), 0);
|
|
}
|
|
|
|
@Test
|
|
void test_html(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
try {
|
|
HtmlGenerator.generateHTML(config1);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void test_html2(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XC); //incompatible
|
|
config1.selectPart(IS); //incompatible
|
|
config1.getPart(exterior).setProperty("color", "red");
|
|
config1.getPart(interior).setProperty("color", "red");
|
|
try {
|
|
HtmlGenerator.generateHTML(config1);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
void test_html3(){
|
|
ConfigurationImpl config1 = new ConfigurationImpl(cm);
|
|
config1.selectPart(EG210);
|
|
config1.selectPart(TSF7);
|
|
config1.selectPart(XS);
|
|
config1.selectPart(IS);
|
|
config1.getPart(exterior).setProperty("color", "red");
|
|
config1.getPart(interior).setProperty("color", "red");
|
|
try {
|
|
HtmlGenerator.generateHTML(config1);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} |